-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First code to repo #1
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have gone through an overview of the PR and have requested some changes. There are a couple of things you should do in addition to these changes:
Push the data files as well as part of this PR (it would be easier for me to clone and test out your repo, and check functionality that way),
Add the Problem Statement shared with you to the README.md file along with a Usage Section where you should add the commands to run to generate the monthly, yearly etc reports,
Also go through pep8 conventions here https://www.python.org/dev/peps/pep-0008/, there are many docstring/variables/indentation issues that you will find here, please address them.
If you have any questions, please feel free to ask!
weatherman.py
Outdated
import pandas as pd | ||
import os | ||
import argparse | ||
import sys | ||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imports should be ordered alphabetically.
weatherman.py
Outdated
import numpy as np | ||
|
||
|
||
os.system("clear") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the purpose of this?
weatherman.py
Outdated
os.system("clear") | ||
|
||
|
||
class WeatherData: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a Docstring
to the class describing what this class holds.
weatherman.py
Outdated
def add_month_data(self, month: int, year: int, | ||
month_data: pd.DataFrame): | ||
if not (0 < month < 13): | ||
print("Invalid month ", month, ". Data not added") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to return
here. Or else the rest of the code will be executed.
weatherman.py
Outdated
self.__mean_humidity = " Mean Humidity" | ||
return | ||
|
||
def add_month_data(self, month: int, year: int, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add Docstring to method describing what arguments and outputs it gives, and what is its purpose!
weatherman.py
Outdated
min_temp_column = weather_data.get_column_data(col_name, | ||
month, year) | ||
max_len = len(max_temp_column) | ||
min_len = len(min_temp_column) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this variable represent? it is not clear from name.
weatherman.py
Outdated
len_ = max_len | ||
if max_len != min_len: | ||
if min_len < max_len: | ||
len_ = min_len | ||
print_str = "\033[1;31;40m Note: Unequal data of maximum" | ||
print_str += " and minimum temperature" | ||
print(print_str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this piece of code doing? maybe move this to a separate method!
weatherman.py
Outdated
suffix_text = str("\033[0;37;40m%.2d " % (i+1)) | ||
low_print = "\033[0;34;40m" + "+"*abs(int(min_temp_column[i])) | ||
high_print = "\033[0;31;40m" + "+"*abs(int(max_temp_column[i])) | ||
add_text = "\033[0;34;40m " | ||
add_text += (str(min_temp_column[i]) + "C\033[1;37;40m-") | ||
add_text += ("\033[0;31;40m" + str(max_temp_column[i]) + "C") | ||
text = suffix_text + low_print + high_print + add_text | ||
print(text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better variable names needed here, maybe move this to a seperate method as well.
weatherman.py
Outdated
return | ||
|
||
|
||
def list_all_files(path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add docstring here.
weatherman.py
Outdated
|
||
|
||
def load_data_from_file(filename): | ||
name, ext = os.path.splitext(filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add docstring here.
…d README.md and requirements.txt. Added DOCStrings to all methods and classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed the PR. Requested some changes, please have look. Here are some other points to cater:
- add a
.gitignore
file (read about what it does), and add the weather data files to it (and any other extra files not needed as part of code), - add
requirements.txt
file with all the requirements to run this code, - Docstrings are not in the correct format throughout the code, please revisit the pep8 conventions,
- Remove the usage of
pandas
andnumpy
, and redesign the code to compute the reports by itself, without help of external packages.
If you have any questions, please free feel to ask!
### Install virtualenv and virtualenvwrapper | ||
_pip install virtualenv_ | ||
|
||
_pip install virtualenvwrapper_ | ||
### Add variables to path (Recommended) | ||
|
||
export WORKON_HOME=$HOME/.virtualenv | ||
|
||
export PROJECT_HOME=$HOME/projects | ||
### Find virtualenvwrapper and run it | ||
_which virtualenvwrapper.sh_ | ||
|
||
_The command will output a path similar to this "/usr/local/bin/virtualenvwrapper.sh"_ | ||
|
||
Enter the following command to run this file | ||
|
||
_source /usr/local/bin/virtualenvwrapper.sh_ | ||
|
||
### Reload startup file ".bashrc" | ||
_source ~/.bashrc_ | ||
|
||
### Create a new virtual environment | ||
_mkvirtualenv env-name_ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use venv
for virtual envirnoment setup. It is much easier to use
https://docs.python.org/3/library/venv.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dont need all the commands related to the virutal envirnoment here, we are only cocerned with our usage. Simplify this to having steps like
- command to install virtualenv,
- command to activate virtualenv,
- command to install requirements of project from
requirement.txt
WeatherData.py
Outdated
add_month_data(self, month, year, month_data) | ||
self: object in which you want to add data | ||
month: integer range(1-12) | ||
year: integer representing year | ||
month_data: pandas data frame having data of all days | ||
|
||
Stores month weather information in data structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the correct format for a docstring. Please check pep8
WeatherData.py
Outdated
Pass alias to get column name | ||
Valid aliases are | ||
max_temperature | ||
min_temperature | ||
max_humidity | ||
min_humidity | ||
mean_humidity | ||
|
||
Returns column name for other function from alias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check docstring format from pep8
common.py
Outdated
return month and year from combined string | ||
|
||
month and year should be numbers and separated with / | ||
Examples: | ||
input string: 12/2006 | ||
output: 12, 2006 | ||
input string: jan/2006 | ||
output: None, None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check docstring format.
common.py
Outdated
month = int(month) | ||
year = int(year) | ||
except Exception: | ||
print("Invalid input") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add more information to this print statement, include reason why the input is invalid.
common.py
Outdated
if number == 1: | ||
return "Jan" | ||
elif number == 2: | ||
return "Feb" | ||
elif number == 3: | ||
return "Mar" | ||
elif number == 4: | ||
return "Apr" | ||
elif number == 5: | ||
return "May" | ||
elif number == 6: | ||
return "Jun" | ||
elif number == 7: | ||
return "Jul" | ||
elif number == 8: | ||
return "Aug" | ||
elif number == 9: | ||
return "Sep" | ||
elif number == 10: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have a dict mapping here instead of if/else statements.
common.py
Outdated
get_column_data_from_alias(weather_data, alias) | ||
alias: Alias of column | ||
Returns complete column data from alias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring
generate_reports.py
Outdated
TEXT_STYLE_NORMAL = 0 | ||
TEXT_STYLE_BOLD = 1 | ||
TEXT_STYLE_LIGHT = 2 | ||
TEXT_STYLE_ITALICIZED = 3 | ||
TEXT_STYLE_UNDERLINED = 4 | ||
TEXT_STYLE_BLINK = 5 | ||
|
||
TEXT_COLOR_BLACK = 30 | ||
TEXT_COLOR_RED = 31 | ||
TEXT_COLOR_GREEN = 32 | ||
TEXT_COLOR_YELLOW = 33 | ||
TEXT_COLOR_BLUE = 34 | ||
TEXT_COLOR_PURPLE = 35 | ||
TEXT_COLOR_CYAN = 36 | ||
TEXT_COLOR_WHITE = 37 | ||
|
||
BACKGROUND_COLOR_BLACK = 40 | ||
BACKGROUND_COLOR_RED = 41 | ||
BACKGROUND_COLOR_GREEN = 42 | ||
BACKGROUND_COLOR_YELLOW = 43 | ||
BACKGROUND_COLOR_BLUE = 44 | ||
BACKGROUND_COLOR_PURPLE = 45 | ||
BACKGROUND_COLOR_CYAN = 46 | ||
BACKGROUND_COLOR_WHITE = 47 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move these to another file, name it constants
or settings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have so many of these colors and fonts, are we using all of them?
generate_reports.py
Outdated
This functions returns a string. Add this string in the start | ||
of the string whose color or style you want to change | ||
|
||
change_text_color(style, color, background_color) | ||
style: changes style, default style "Normal" | ||
color: changes text color, default color "White" | ||
background_color: changes background color, default "Black" | ||
|
||
Pass constants in the function, string colors are not allowed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check pep8 docstring format.
generate_reports.py
Outdated
BACKGROUND_COLOR_WHITE = 47 | ||
|
||
|
||
def change_text_color(style=0, color=37, background_color=40): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve function name, not clear what the function is doing from reading the name!
…irements.txt. Added .gitignore. Updated docstrings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments, please resolve them!
Why are there 2d arrays?
common.py
Outdated
@@ -0,0 +1,105 @@ | |||
def get_month_year_from_string(string): | |||
"""Returns month and year from combined string | |||
month and year should be numbers and separated with / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/
-> slash
common.py
Outdated
mapping_dictionary = { | ||
"jan": 1, | ||
"feb": 2, | ||
"mar": 3, | ||
"apr": 4, | ||
"may": 5, | ||
"jun": 6, | ||
"jul": 7, | ||
"aug": 8, | ||
"sep": 9, | ||
"oct": 10, | ||
"nov": 11, | ||
"dec": 12 | ||
} | ||
return mapping_dictionary.get(string, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this mapping to constants file.
common.py
Outdated
|
||
string = str(string).lower() | ||
# Map month name to number | ||
mapping_dictionary = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this variable represent? name should be more descriptive!
common.py
Outdated
mapping_dictionary = { | ||
1: "Jan", | ||
2: "Feb", | ||
3: "Mar", | ||
4: "Apr", | ||
5: "May", | ||
6: "Jun", | ||
7: "Jul", | ||
8: "Aug", | ||
9: "Sep", | ||
10: "Oct", | ||
11: "Nov", | ||
12: "Dec" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to constants.
You can use a single dict for the mapping, instead of having 2 different dicts.
common.py
Outdated
return mapping_dictionary.get(string, None) | ||
|
||
|
||
def get_month_string_from_number(number: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change number
to a better variable name!
generate_reports.py
Outdated
return color_string | ||
|
||
|
||
def arg_max(list_): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name of function needs to be more descriptive!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input name needs to be more descriptive!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is there an underscore after the input variable name?
generate_reports.py
Outdated
if not list_: | ||
return None | ||
max_index = 0 | ||
max_value = list_[max_index] | ||
for i in range(0, len(list_)): | ||
if list_[i] > max_value: | ||
max_value = list_[i] | ||
max_index = i | ||
return max_index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is happening in this method? Can we not do this computation with lists, instead of needing a separate function?
generate_reports.py
Outdated
"""Returns the index of minimum element of list | ||
|
||
Arguments: | ||
list_: | ||
list whose minimum index is required | ||
|
||
Returns: | ||
index: int: | ||
The index whose value is minimum | ||
""" | ||
|
||
if not list_: | ||
return None | ||
min_index = 0 | ||
min_value = list_[min_index] | ||
for i in range(0, len(list_)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same concerns as for the method arg_min
generate_reports.py
Outdated
return min_index | ||
|
||
|
||
def get_boundary_element(list_, max_=True, index=0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are there underscores after the variables here?
generate_reports.py
Outdated
month, year) | ||
if max_temp_column: | ||
max_index = arg_max(max_temp_column) | ||
max_temp_list.append([max_temp_column[max_index], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is happening here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beyond other suggested changes I would like to see if you can add unit tests for the project.
WeatherData.py
Outdated
self.__max_humidity = "Max Humidity" | ||
self.__min_humidity = " Min Humidity" | ||
self.__mean_humidity = " Mean Humidity" | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need return here
constants.py
Outdated
BACKGROUND_COLOR_WHITE = 47 | ||
|
||
|
||
month_number_string_mapping = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uses CAPS for constants.
generate_reports.py
Outdated
load_year_data(weather_data, path, year) | ||
|
||
# Checking data of all 12 months | ||
for i in range(0, 12): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
month in range(1,13)
can be used , month
variable month = i +1
can be removed
max_temp_column = get_column_data_from_alias(weather_data, | ||
"max_temperature", | ||
month, year) | ||
if max_temp_column: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 141 to 145 look similar to 151 to 157 see if it can be extracted in functions.
Complete code of the assignment