From 9ed24ad70267877f4e851de7080e6eb3941a17e2 Mon Sep 17 00:00:00 2001 From: Haroon Chughtai Date: Tue, 10 Nov 2020 15:48:17 +0000 Subject: [PATCH 01/20] Code and structure for week06 docs exercises --- .../average_squares/squares.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 week06/average-squares-example/average_squares/squares.py diff --git a/week06/average-squares-example/average_squares/squares.py b/week06/average-squares-example/average_squares/squares.py new file mode 100644 index 0000000..d7e454e --- /dev/null +++ b/week06/average-squares-example/average_squares/squares.py @@ -0,0 +1,62 @@ +"""Computation of weighted average of squares.""" + + +def average_of_squares(list_of_numbers, list_of_weights=None): + """ Return the weighted average of a list of values. + + By default, all values are equally weighted, but this can be changed + by the list_of_weights argument. + + Example: + -------- + >>> average_of_squares([1, 2, 4]) + 7.0 + >>> average_of_squares([2, 4], [1, 0.5]) + 6.0 + >>> average_of_squares([1, 2, 4], [1, 0.5]) + Traceback (most recent call last): + AssertionError: weights and numbers must have same length + + """ + if list_of_weights is not None: + assert len(list_of_weights) == len(list_of_numbers), \ + "weights and numbers must have same length" + effective_weights = list_of_weights + else: + effective_weights = [1] * len(list_of_numbers) + squares = [ + weight * number * number + for number, weight + in zip(list_of_numbers, effective_weights) + ] + return sum(squares) + + +def convert_numbers(list_of_strings): + """Convert a list of strings into numbers, ignoring whitespace. + + Example: + -------- + >>> convert_numbers(["4", " 8 ", "15 16", " 23 42 "]) + [4, 8, 15, 16] + + """ + all_numbers = [] + for s in list_of_strings: + # Take each string in the list, split it into substrings separated by + # whitespace, and collect them into a single list... + all_numbers.extend([token.strip() for token in s.split()]) + # ...then convert each substring into a number + return [float(number_string) for number_string in all_numbers] + + +if __name__ == "__main__": + numbers_strings = ["1","2","4"] + weight_strings = ["1","1","1"] + + numbers = convert_numbers(numbers_strings) + weights = convert_numbers(weight_strings) + + result = average_of_squares(numbers, weights) + + print(result) \ No newline at end of file From a82f8309377fdf4c5c4b7187b8b84ebe6da58d12 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 20:52:50 +0000 Subject: [PATCH 02/20] Fixing error in average of squares --- .../__pycache__/squares.cpython-38.pyc | Bin 0 -> 2029 bytes .../average_squares/squares.py | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 week06/average-squares-example/average_squares/__pycache__/squares.cpython-38.pyc diff --git a/week06/average-squares-example/average_squares/__pycache__/squares.cpython-38.pyc b/week06/average-squares-example/average_squares/__pycache__/squares.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3a7ed04aa3d31c84feb4c74d6029ec65a6e155af GIT binary patch literal 2029 zcma)7-EP}96ecNIR-7e4gIuizMx;OyVNUFLPFfU!_mlQE7?u_olm&t!(z0M#azrX= z4CiLf3+xS=%iRpvBkVPFyPNG51`OSyew;K7*3uwFQ9R^#zVn^q*Go$c1nuj;esk

66Ryv& zZNRez&pOB4;Pn}?O}@a*8ODg=Lu4&ZzTA&T<5apbh$9;J={XPlf#i(3XFPFzuGYk9 z>Ly%l9e4!5R85D8>if{e_b^N`!^4H-iG*-eee|P6wn^ak~ zw{}XS-H#YmSKPIGmAD>1alIkk7{$P0!aeW?2mr1^S4gXH<69wkq6G3XN#f*r$r-pG zF&d?#6P^eA!25mf z$>5AvYPIVn$QvG#8eq#-Kg6Xli!~U~0~4=e@=hlPS;mHD{%h2dMOgnJMg}bArJxHF zA6?=pdV!7~L5%QQC^n2-L5jb{*RVRn*HC~?O{V3mSgk<1>yzL2;|R)*q&GP&WD-Qa zpg|<#N^DIU_))CZ>G>d#T#P}+pPYkUafee^H5m_i zbSE;2;tKa5>jVzQSChMXb<_hIYY#%7Vs;BO?4 z82C0018HeDvMj@BFG6Xln9s1db7;15$Gyku0uu(bpkq_}oFuC-&rHV|xk2PO8Q#ut zC&OI}A6Sj7?l>&=94A-kd}{;+$#LwJGT@~@!d@O#uw(Qi5s{ Date: Fri, 13 Nov 2020 20:59:59 +0000 Subject: [PATCH 03/20] Converting float to integer --- week06/average-squares-example/average_squares/squares.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/week06/average-squares-example/average_squares/squares.py b/week06/average-squares-example/average_squares/squares.py index f73753e..fea6565 100644 --- a/week06/average-squares-example/average_squares/squares.py +++ b/week06/average-squares-example/average_squares/squares.py @@ -48,8 +48,7 @@ def convert_numbers(list_of_strings): # whitespace, and collect them into a single list... all_numbers.extend([token.strip() for token in s.split()]) # ...then convert each substring into a number - return [float(number_string) for number_string in all_numbers] - + return [int(number_string) for number_string in all_numbers] if __name__ == "__main__": numbers_strings = ["1","2","4"] From de26d4a9e94fc1fabfca4987e9a7bd369970bf87 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 21:21:57 +0000 Subject: [PATCH 04/20] Fixing expected of convert_numbers --- week06/average-squares-example/average_squares/squares.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week06/average-squares-example/average_squares/squares.py b/week06/average-squares-example/average_squares/squares.py index fea6565..6279815 100644 --- a/week06/average-squares-example/average_squares/squares.py +++ b/week06/average-squares-example/average_squares/squares.py @@ -39,7 +39,7 @@ def convert_numbers(list_of_strings): Example: -------- >>> convert_numbers(["4", " 8 ", "15 16", " 23 42 "]) - [4, 8, 15, 16] + [4, 8, 15, 16, 23, 42] """ all_numbers = [] From b92c022035920c676f22fd72c5b68af348aefed6 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:13:28 +0000 Subject: [PATCH 05/20] Adding the .rst file under docs/content --- .../docs/content /average-square-docs.rst | 0 .../docs/source/index.rst | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 week06/average-squares-example/docs/content /average-square-docs.rst create mode 100644 week06/average-squares-example/docs/source/index.rst diff --git a/week06/average-squares-example/docs/content /average-square-docs.rst b/week06/average-squares-example/docs/content /average-square-docs.rst new file mode 100644 index 0000000..e69de29 diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst new file mode 100644 index 0000000..4d21149 --- /dev/null +++ b/week06/average-squares-example/docs/source/index.rst @@ -0,0 +1,22 @@ +.. documentation documentation master file, created by + sphinx-quickstart on Fri Nov 13 21:51:39 2020. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to documentation's documentation! +========================================= + +Purpose of the project is to find the average squares and also convert numbers +.. toctree:: + Average square documentation + :maxdepth: 2 + :caption: Contents: + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` From a8da7a2e4b7f568eef6360acdb48a893d1d08322 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:16:06 +0000 Subject: [PATCH 06/20] Adding .rst file under docs/content ( ight file) --- .../docs/content /average-square-docs.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/week06/average-squares-example/docs/content /average-square-docs.rst b/week06/average-squares-example/docs/content /average-square-docs.rst index e69de29..3b0be8e 100644 --- a/week06/average-squares-example/docs/content /average-square-docs.rst +++ b/week06/average-squares-example/docs/content /average-square-docs.rst @@ -0,0 +1,2 @@ +Average Squares Documentation +============================= From 46a33f5163b712e7e8af954f109e86d750d7e184 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:25:02 +0000 Subject: [PATCH 07/20] Fixing how to refer to .rst file --- week06/average-squares-example/docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst index 4d21149..b7760c2 100644 --- a/week06/average-squares-example/docs/source/index.rst +++ b/week06/average-squares-example/docs/source/index.rst @@ -8,7 +8,7 @@ Welcome to documentation's documentation! Purpose of the project is to find the average squares and also convert numbers .. toctree:: - Average square documentation + average-square-docs :maxdepth: 2 :caption: Contents: From a2b6b62f0faded77fae125c258722d14bb4087ca Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:26:28 +0000 Subject: [PATCH 08/20] Revert "Fixing how to refer to .rst file" This reverts commit 46a33f5163b712e7e8af954f109e86d750d7e184. --- week06/average-squares-example/docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst index b7760c2..4d21149 100644 --- a/week06/average-squares-example/docs/source/index.rst +++ b/week06/average-squares-example/docs/source/index.rst @@ -8,7 +8,7 @@ Welcome to documentation's documentation! Purpose of the project is to find the average squares and also convert numbers .. toctree:: - average-square-docs + Average square documentation :maxdepth: 2 :caption: Contents: From 92d9fedae6f08161789c5933740427c3c8458a6a Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:29:07 +0000 Subject: [PATCH 09/20] Fixing how to refer to .rst file --- week06/average-squares-example/docs/source/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst index 4d21149..b141880 100644 --- a/week06/average-squares-example/docs/source/index.rst +++ b/week06/average-squares-example/docs/source/index.rst @@ -8,10 +8,11 @@ Welcome to documentation's documentation! Purpose of the project is to find the average squares and also convert numbers .. toctree:: - Average square documentation :maxdepth: 2 :caption: Contents: + average-square-docs.rst + Indices and tables From 41180f9c765ea67fb03b029be621f0346f036146 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:33:37 +0000 Subject: [PATCH 10/20] Trying again - --- week06/average-squares-example/docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst index b141880..89c8b44 100644 --- a/week06/average-squares-example/docs/source/index.rst +++ b/week06/average-squares-example/docs/source/index.rst @@ -11,7 +11,7 @@ Purpose of the project is to find the average squares and also convert numbers :maxdepth: 2 :caption: Contents: - average-square-docs.rst + From 50e7ba677983672dda08c7374d5a108e1bd58995 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:39:10 +0000 Subject: [PATCH 11/20] Another try to refer to file --- week06/average-squares-example/docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst index 89c8b44..43ed513 100644 --- a/week06/average-squares-example/docs/source/index.rst +++ b/week06/average-squares-example/docs/source/index.rst @@ -11,7 +11,7 @@ Purpose of the project is to find the average squares and also convert numbers :maxdepth: 2 :caption: Contents: - + :ref:`Average Square Documentation` From f30ee9f5aafbf6551df476c6a61ad0656474d2b5 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:44:21 +0000 Subject: [PATCH 12/20] Adding space between title and toctree --- week06/average-squares-example/docs/source/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst index 43ed513..3101184 100644 --- a/week06/average-squares-example/docs/source/index.rst +++ b/week06/average-squares-example/docs/source/index.rst @@ -7,6 +7,7 @@ Welcome to documentation's documentation! ========================================= Purpose of the project is to find the average squares and also convert numbers + .. toctree:: :maxdepth: 2 :caption: Contents: From cea0d71ce8b05302ae220c1363dbfa4bc8a2de76 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:46:17 +0000 Subject: [PATCH 13/20] Adding link after fixing space --- week06/average-squares-example/docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst index 3101184..dc04848 100644 --- a/week06/average-squares-example/docs/source/index.rst +++ b/week06/average-squares-example/docs/source/index.rst @@ -12,7 +12,7 @@ Purpose of the project is to find the average squares and also convert numbers :maxdepth: 2 :caption: Contents: - :ref:`Average Square Documentation` + `Average Square Documentation` From 4788866343254fb978596c953a9ca14416742af8 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:47:51 +0000 Subject: [PATCH 14/20] Adding space between last word and <, remove ` --- week06/average-squares-example/docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst index dc04848..6995f04 100644 --- a/week06/average-squares-example/docs/source/index.rst +++ b/week06/average-squares-example/docs/source/index.rst @@ -12,7 +12,7 @@ Purpose of the project is to find the average squares and also convert numbers :maxdepth: 2 :caption: Contents: - `Average Square Documentation` + Average Square Documentation From 502036875b59b2647cb85294df22d3f48861bc4c Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:49:10 +0000 Subject: [PATCH 15/20] Add .rst at the end --- week06/average-squares-example/docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst index 6995f04..cfcf01b 100644 --- a/week06/average-squares-example/docs/source/index.rst +++ b/week06/average-squares-example/docs/source/index.rst @@ -12,7 +12,7 @@ Purpose of the project is to find the average squares and also convert numbers :maxdepth: 2 :caption: Contents: - Average Square Documentation + Average Square Documentation From c7fa5b56ae5bf7eb4e02b2606e7e33c15d31a3f2 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:54:00 +0000 Subject: [PATCH 16/20] Listing the name of document only --- week06/average-squares-example/docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week06/average-squares-example/docs/source/index.rst b/week06/average-squares-example/docs/source/index.rst index cfcf01b..e5a3e3a 100644 --- a/week06/average-squares-example/docs/source/index.rst +++ b/week06/average-squares-example/docs/source/index.rst @@ -12,7 +12,7 @@ Purpose of the project is to find the average squares and also convert numbers :maxdepth: 2 :caption: Contents: - Average Square Documentation + average-square-docs From 7c33f54de530be37ee54344e513628833ee478f1 Mon Sep 17 00:00:00 2001 From: Vivian Date: Fri, 13 Nov 2020 23:57:36 +0000 Subject: [PATCH 17/20] Adding .rst file under same directory as index.rst --- .../average-squares-example/docs/source/average-square-docs.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 week06/average-squares-example/docs/source/average-square-docs.rst diff --git a/week06/average-squares-example/docs/source/average-square-docs.rst b/week06/average-squares-example/docs/source/average-square-docs.rst new file mode 100644 index 0000000..3b0be8e --- /dev/null +++ b/week06/average-squares-example/docs/source/average-square-docs.rst @@ -0,0 +1,2 @@ +Average Squares Documentation +============================= From d8cd6a8b91656b3303bfcb241cf04b30323f4d38 Mon Sep 17 00:00:00 2001 From: Vivian Date: Sat, 14 Nov 2020 00:01:02 +0000 Subject: [PATCH 18/20] Activating autodoc --- .../docs/source/conf.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 week06/average-squares-example/docs/source/conf.py diff --git a/week06/average-squares-example/docs/source/conf.py b/week06/average-squares-example/docs/source/conf.py new file mode 100644 index 0000000..74f1c64 --- /dev/null +++ b/week06/average-squares-example/docs/source/conf.py @@ -0,0 +1,55 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'documentation' +copyright = '2020, Regina Vivian Barli' +author = 'Regina Vivian Barli' + +# The full version, including alpha/beta/rc tags +release = '0.0.1' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = ['sphinx.ext.autodoc' +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] \ No newline at end of file From b60e4a3b197563dd08f6f357cf1815fa891cadc1 Mon Sep 17 00:00:00 2001 From: Vivian Date: Sat, 14 Nov 2020 00:09:11 +0000 Subject: [PATCH 19/20] Modifying the path --- .../docs/content /average-square-docs.rst | 1 + week06/average-squares-example/docs/source/conf.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/week06/average-squares-example/docs/content /average-square-docs.rst b/week06/average-squares-example/docs/content /average-square-docs.rst index 3b0be8e..58d091d 100644 --- a/week06/average-squares-example/docs/content /average-square-docs.rst +++ b/week06/average-squares-example/docs/content /average-square-docs.rst @@ -1,2 +1,3 @@ Average Squares Documentation ============================= +.. autofunction:: average_of_squares \ No newline at end of file diff --git a/week06/average-squares-example/docs/source/conf.py b/week06/average-squares-example/docs/source/conf.py index 74f1c64..ee38048 100644 --- a/week06/average-squares-example/docs/source/conf.py +++ b/week06/average-squares-example/docs/source/conf.py @@ -10,9 +10,9 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # -# import os -# import sys -# sys.path.insert(0, os.path.abspath('.')) +import os +import sys +sys.path.insert(0, os.path.abspath('.')) # -- Project information ----------------------------------------------------- From eca0d6859833ae54f071af429faa153effe98781 Mon Sep 17 00:00:00 2001 From: Vivian Date: Sat, 14 Nov 2020 00:15:04 +0000 Subject: [PATCH 20/20] Modifying the path under source --- .../average-squares-example/docs/source/average-square-docs.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/week06/average-squares-example/docs/source/average-square-docs.rst b/week06/average-squares-example/docs/source/average-square-docs.rst index 3b0be8e..58d091d 100644 --- a/week06/average-squares-example/docs/source/average-square-docs.rst +++ b/week06/average-squares-example/docs/source/average-square-docs.rst @@ -1,2 +1,3 @@ Average Squares Documentation ============================= +.. autofunction:: average_of_squares \ No newline at end of file