Skip to content

Implement Weather functionality - #1

Open
developer-jawad wants to merge 18 commits into
masterfrom
dev
Open

Implement Weather functionality#1
developer-jawad wants to merge 18 commits into
masterfrom
dev

Conversation

@developer-jawad

Copy link
Copy Markdown
Owner

… than comparison there is no value is set in required date because both temperature are same. remove this bug and when i return object from _calculateTemperatureWithField function it return the last file it is read alse remove this bug

@m-Hariss m-Hariss changed the title fix: in _calculateInfoFromFile when compare for greater than and less… Implement Weather functionality May 23, 2024

@m-Hariss m-Hariss left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good work @developer-jawad! We can make following improvements:.

  • Use meaningful naming conventions.
  • Use a bit more smart and cleaner strategy.
  • Functions to be as less coupled with each as possible (does not mean avoid dividing tasks into functions, but it should not be dependant of how the one caller calling functions. It just be aware of what its provided with and what is expected from it.).
  • Can use different files for different functionality and data.
  • Handle exceptions carefully, application must not crash at all.
  • Use brief and to the point commit messages (as suggested). Like:
    fix: in _calculateInfoFromFile when compare for greater than and less than comparison there is no value is set in required date because both temperature are same. remove this bug and when i return object from _calculateTemperatureWithField function it return the last file it is read alse remove this bug
    can be just
    fix: temperate comparison in calculating information
    or this (in case need a detailed one):
     fix: resolve issues in _calculateInfoFromFile and _calculateTemperatureWithField
    
    - Correct comparison logic in _calculateInfoFromFile: Ensure the required date is set correctly even when both temperatures are the same.
    - Fix _calculateTemperatureWithField to return the correct file: Ensure the function returns the appropriate file instead of the last file read.
    

Comment thread main.py Outdated
Comment thread main.py Outdated
Comment thread main.py Outdated
Comment on lines +56 to +57
if len(self.data) == 0:
raise Exception("No file is found")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can this be out of if/else?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

no, it is not outside the if condition because when there is not file exists with the name of given month then it will raise an exception

Comment thread main.py Outdated
"""
def readDataFromSingleFile(self, month):
try :
with open(f'weather_reports/Murree_weather_{self.year}_{month}.txt', 'r') as file:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can file path be a constants?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

no file paths are not constants year and month are dynamic which coming from user

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What if we use Format() here?

Comment thread main.py
Comment thread main.py Outdated
Comment thread main.py Outdated
Comment thread main.py Outdated

return required_data

def _calculateInfoFromFile(self, single_file_record, field, maxNumber):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we make the classes and functions be independent of whether the data was loaded from file or db or any other source?

Comment thread main.py Outdated
Comment thread main.py Outdated
Comment on lines +232 to +233
if len(splitted_file_date) >= 2:
bar_count = int(input("Please Enter Number of Report bar_counts 1-2: "))

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

it is used to display report in one horizontal bar or 2 horizontal bars

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lets use Command Line Arguments as in examples mentioned in task?

Comment thread main.py Outdated
Comment on lines +38 to +39
if len(self.data) == 0:
raise Exception("No file is found")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

https://github.com/developer-jawad/Weatherman/pull/1/files#r1615940065

We have code duplication, if we keep it inside if/else. Thought?

Comment thread main.py Outdated
"""
def readDataFromSingleFile(self, month):
try :
with open(f'weather_reports/Murree_weather_{self.year}_{month}.txt', 'r') as file:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What if we use Format() here?

Comment thread main.py Outdated
Comment on lines +100 to +111
if type_of_calculation == 'H':
return self._calculateTemperatureWithField('Max TemperatureC', True)
elif type_of_calculation == 'L':
return self._calculateTemperatureWithField('Min TemperatureC', False)
elif type_of_calculation == 'Hu':
return self._calculateTemperatureWithField('Max Humidity', True)
elif type_of_calculation == 'avg_L':
return self._calculateTemperatureWithField('Mean TemperatureC', False)
elif type_of_calculation == 'avg_H':
return self._calculateTemperatureWithField('Mean TemperatureC', True)
elif type_of_calculation == 'avg_Hu':
return self._calculateTemperatureWithField('Max Humidity', True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What if we use Dict here. Thought?

Comment thread main.py Outdated
Comment on lines +232 to +233
if len(splitted_file_date) >= 2:
bar_count = int(input("Please Enter Number of Report bar_counts 1-2: "))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lets use Command Line Arguments as in examples mentioned in task?

Comment thread main.py Outdated
Comment thread main.py Outdated
Comment thread main.py Outdated
Comment thread main.py Outdated
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.

2 participants