-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from vfedotovs/staging-rc-1.4.7
Staging rc 1.4.7
- Loading branch information
Showing
17 changed files
with
383 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env python3 | ||
""" DataAnalyzer creates statistical text segments and images for report | ||
DataAnalyzer provides functionality to extract statistical data segments | ||
and create statistical images from data frame and postgress database. | ||
Module requires: | ||
* cleaned-sorted-df.csv - contains scraped data | ||
Module creates: | ||
* daily_room_type_stats.txt | ||
Todo: | ||
* [ ] Create str segments (most of algos are in jupyter) | ||
- [ ] rooms types % | ||
- [ ] house floors | ||
- [ ] apt locations | ||
- [ ] sqm size ranges for each | ||
- [ ] sqm price ranges for each | ||
* [ ] Create images based on DF | ||
- [ ] gen_image(data_frame, 'Size_sqm', "Price_in_eur") - created but df not filtered by room cunt = 1 | ||
- [ ] gen_image('double_room_sqm_prices.png') | ||
- [ ] gen_image('triple_room_sqm_prices.png') | ||
- [ ] gen_image('quad_room_sqm_prices.png') | ||
- [] gen_image('all_room_sqm_prices.png') | ||
* Need interface to connect to DB and extract historic dict and save to to df and csv | ||
""" | ||
import pandas as pd | ||
|
||
|
||
class DataFrameAvalyzer(): | ||
|
||
def __init__(self, df_file_name: str): | ||
self.df_file_name = df_file_name | ||
|
||
def analyze_df_room_types(self, file) -> None: | ||
pass | ||
|
||
def analyze_df_house_types(self, file) -> None: | ||
pass | ||
|
||
def analyze_df_apt_loc_types(self, file) -> None: | ||
pass | ||
|
||
|
||
def gen_image(self, data_frame: pd.DataFrame, xclmn: str, yclmn: str) -> None: | ||
"""Generate scatter plot based x and y axsis as data frame column values, | ||
include title and save to *.png file""" | ||
img_title = 'All room sqm size to price relationships' | ||
#file_name = '{}_{}.png'.format(xclmn, yclmn) | ||
file_name = 'all_room_sqm_prices.png' | ||
ax = data_frame.plot.scatter( | ||
x=xclmn, y=yclmn, s=100, title=img_title, grid=True) | ||
fig = ax.get_figure() | ||
fig.savefig(file_name) | ||
|
||
|
||
class DBAnalyzer(): | ||
pass | ||
|
||
|
||
def main(): | ||
"""docstring""" | ||
run_daily_analitics() | ||
run_monthly_analitics() | ||
|
||
|
||
def run_daily_analitics() -> None: | ||
"""docstring""" | ||
data_frame = pd.read_csv('cleaned-sorted-df.csv') | ||
dfa = DataFrameAvalyzer('cleaned-sorted-df.csv') | ||
#dfa.analyze_df_room_types('daily_room_stats.txt') | ||
#dfa.analyze_df_house_types('daily_house_stats.txt') | ||
#dfa.analyze_df_apt_loc_types('daily_apt_loc_stats.txt') | ||
#dfa.gen_image(data_frame, 'Size_sqm', "Price_in_eur") | ||
#dfa.gen_image('double_room_sqm_prices.png') | ||
#dfa.gen_image('triple_room_sqm_prices.png') | ||
#dfa.gen_image('quad_room_sqm_prices.png') | ||
dfa.gen_image(data_frame, 'Size_sqm', "Price_in_eur") | ||
|
||
|
||
def run_monthly_analitics() -> None: | ||
"""docstring""" | ||
pass | ||
|
||
|
||
main() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" FIXME module docstring """ | ||
from datetime import datetime | ||
from time import strftime | ||
from fpdf import FPDF | ||
|
||
|
||
class Report(): | ||
""" docsting """ | ||
|
||
def __init__(self, report_type, file_name): | ||
self.report_type = report_type | ||
self.file_name = file_name | ||
self.pdf = FPDF() | ||
self.pdf.add_page() | ||
self.pdf.set_font('Arial', 'B', 16) | ||
#self.insert_header(self.report_type) | ||
|
||
def insert_header(self, report_type: str) -> None: | ||
""" docstring """ | ||
todays_date = datetime.today().strftime('%Y-%m-%d %H:%M') | ||
report_title = f"Ogre city apartments for sale {report_type}" | ||
date_created = f"Report date: {todays_date}" | ||
self.pdf.write(5, report_title) | ||
self.pdf.ln(5) | ||
self.pdf.write(5, date_created) | ||
self.pdf.ln(5) | ||
|
||
def insert_text_segment(self, text_lines: str) -> None: | ||
""" docstring """ | ||
self.pdf.ln(5) # line break | ||
self.pdf.write(5, text_lines) | ||
self.pdf.ln(5) | ||
|
||
def insert_error_msg(self, msg: str) -> None: | ||
""" docstring """ | ||
self.pdf.ln(5) # line break | ||
self.pdf.write(5, msg) | ||
self.pdf.ln(5) | ||
|
||
|
||
def insert_images(self, images: list) -> None: | ||
""" docstring """ | ||
for image in images: | ||
self.pdf.image(image, x=10, y=10, w=100, h=100) | ||
self.pdf.ln(5) | ||
|
||
def save_report(self, file_name: str) -> None: | ||
""" docstring """ | ||
self.pdf.output(file_name, 'F') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.