Skip to content

First code to repo#1

Open
muhammadadeeltajamul wants to merge 7 commits into
masterfrom
weatherman
Open

First code to repo#1
muhammadadeeltajamul wants to merge 7 commits into
masterfrom
weatherman

Conversation

@muhammadadeeltajamul
Copy link
Copy Markdown
Owner

Complete code of the assignment

Copy link
Copy Markdown

@saadyousafarbi saadyousafarbi left a 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!

Comment thread weatherman.py Outdated
Comment on lines +1 to +5
import pandas as pd
import os
import argparse
import sys
import numpy as np
Copy link
Copy Markdown

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.

Comment thread weatherman.py Outdated
import numpy as np


os.system("clear")
Copy link
Copy Markdown

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?

Comment thread weatherman.py Outdated
os.system("clear")


class WeatherData:
Copy link
Copy Markdown

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.

Comment thread 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")
Copy link
Copy Markdown

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.

Comment thread weatherman.py Outdated
self.__mean_humidity = " Mean Humidity"
return

def add_month_data(self, month: int, year: int,
Copy link
Copy Markdown

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!

Comment thread 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)
Copy link
Copy Markdown

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.

Comment thread weatherman.py Outdated
Comment on lines +283 to +289
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)
Copy link
Copy Markdown

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!

Comment thread weatherman.py Outdated
Comment on lines +291 to +298
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)
Copy link
Copy Markdown

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.

Comment thread weatherman.py Outdated
return


def list_all_files(path):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add docstring here.

Comment thread weatherman.py Outdated


def load_data_from_file(filename):
name, ext = os.path.splitext(filename)
Copy link
Copy Markdown

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.
Copy link
Copy Markdown

@saadyousafarbi saadyousafarbi left a 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 and numpy, 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!

Comment thread README.md
Comment on lines +73 to +96
### 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_

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Comment thread WeatherData.py Outdated
Comment on lines +31 to +37
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
Copy link
Copy Markdown

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

Comment thread WeatherData.py Outdated
Comment on lines +54 to +62
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
Copy link
Copy Markdown

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

Comment thread common.py Outdated
Comment on lines +3 to +10
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check docstring format.

Comment thread common.py Outdated
month = int(month)
year = int(year)
except Exception:
print("Invalid input")
Copy link
Copy Markdown

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.

Comment thread common.py Outdated
Comment on lines +75 to +93
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:
Copy link
Copy Markdown

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.

Comment thread common.py Outdated
Comment on lines +104 to +106
get_column_data_from_alias(weather_data, alias)
alias: Alias of column
Returns complete column data from alias
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring

Comment thread generate_reports.py Outdated
Comment on lines +9 to +32
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
Copy link
Copy Markdown

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

Copy link
Copy Markdown

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?

Comment thread generate_reports.py Outdated
Comment on lines +37 to +45
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check pep8 docstring format.

Comment thread generate_reports.py Outdated
BACKGROUND_COLOR_WHITE = 47


def change_text_color(style=0, color=37, background_color=40):
Copy link
Copy Markdown

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!

Copy link
Copy Markdown

@saadyousafarbi saadyousafarbi left a 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?

Comment thread 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 /
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ -> slash

Comment thread common.py Outdated
Comment on lines +39 to +53
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)
Copy link
Copy Markdown

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.

Comment thread common.py Outdated

string = str(string).lower()
# Map month name to number
mapping_dictionary = {
Copy link
Copy Markdown

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!

Comment thread common.py Outdated
Comment on lines +68 to +81
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"
}
Copy link
Copy Markdown

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.

Comment thread common.py Outdated
return mapping_dictionary.get(string, None)


def get_month_string_from_number(number: int):
Copy link
Copy Markdown

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!

Comment thread generate_reports.py Outdated
return color_string


def arg_max(list_):
Copy link
Copy Markdown

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!

Copy link
Copy Markdown

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!

Copy link
Copy Markdown

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?

Comment thread generate_reports.py Outdated
Comment on lines +50 to +58
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
Copy link
Copy Markdown

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?

Comment thread generate_reports.py Outdated
Comment on lines +62 to +77
"""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_)):
Copy link
Copy Markdown

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

Comment thread generate_reports.py Outdated
return min_index


def get_boundary_element(list_, max_=True, index=0):
Copy link
Copy Markdown

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?

Comment thread 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],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is happening here?

Copy link
Copy Markdown

@AhtishamShahid AhtishamShahid left a 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.

Comment thread WeatherData.py Outdated
self.__max_humidity = "Max Humidity"
self.__min_humidity = " Min Humidity"
self.__mean_humidity = " Mean Humidity"
return
Copy link
Copy Markdown

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

Comment thread constants.py Outdated
BACKGROUND_COLOR_WHITE = 47


month_number_string_mapping = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses CAPS for constants.

Comment thread generate_reports.py Outdated
load_year_data(weather_data, path, year)

# Checking data of all 12 months
for i in range(0, 12):
Copy link
Copy Markdown

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

Comment thread generate_reports.py
max_temp_column = get_column_data_from_alias(weather_data,
"max_temperature",
month, year)
if max_temp_column:
Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants