Skip to content

Commit

Permalink
Small clenup
Browse files Browse the repository at this point in the history
  • Loading branch information
Galatolol committed Oct 28, 2022
1 parent 311a227 commit 8071058
Show file tree
Hide file tree
Showing 15 changed files with 1,219 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Import the main function:

Execute the function:

`generate_market_heatmaps(csv_market_path='data/1894_market.csv)`
`generate_market_heatmaps(market_path='data/1830_market.html')`

## Parameters

Expand Down
841 changes: 841 additions & 0 deletions data/1841_market.html

Large diffs are not rendered by default.

363 changes: 363 additions & 0 deletions data/18ireland_market.html

Large diffs are not rendered by default.

File renamed without changes
Binary file added examples/1841.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/18ireland.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file removed importer_util.py
Empty file.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path

from process_data import calculate_delta_map
from importer import import_csv_market, import_html_market
from market_import import import_csv_market, import_html_market
from plot import generate_plot


Expand Down Expand Up @@ -60,7 +60,7 @@ def generate_market_heatmaps(


if __name__ == '__main__':
market_path = f'data/1822_market.html'
market_path = 'data/1830_market.html'

generate_market_heatmaps(market_path=market_path, show_market=True, delta_from_left_and_below=True,
delta_from_left=True, delta_from_below=True, color_scheme='gist_ncar')
Expand Down
4 changes: 2 additions & 2 deletions importer.py → market_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def is_alphanum_or_coma_or_newline(x: str) -> bool:
return False


def nan_or_int(x: str) -> int:
def nan_or_int(x: str):
if x in ['\n', 'nan']:
return nan
return int(x)


def parse_html_txt_market(html_txt: str) -> list:
def parse_html_txt_market(html_txt: str) -> list[list]:
html_txt_junk_removed = ''.join([x for x in html_txt if is_alphanum_or_coma_or_newline(x)])
html_txt_newlines_replaced = html_txt_junk_removed.replace('\n\n\n\n\n\n\n', ';').replace('\n\n\n\n\n', ',').strip().replace('\n', '\n,')
rows = html_txt_newlines_replaced.split(';')
Expand Down
4 changes: 2 additions & 2 deletions process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from statistics import mean


def get_cell_value(market: DataFrame, i: int, j: int) -> int:
def get_cell_value(market: DataFrame, i: int, j: int):
try:
if i < 0 or j < 0:
raise IndexError
Expand All @@ -13,7 +13,7 @@ def get_cell_value(market: DataFrame, i: int, j: int) -> int:
return nan


def calculate_delta(value: int, neighbor_values: list) -> float:
def calculate_delta(value: int, neighbor_values: list):
neighbor_values = [x for x in neighbor_values if not isna(x)]
if not neighbor_values:
return nan
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
matplotlib>=3.6
numpy>=1.23
pandas>=1.5.1
seaborn>=0.12.1
pandas>=1.5
seaborn>=0.12
beautifulsoup4>=4.1
Binary file removed test/__pycache__/test_importer.cpython-310.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion test/test_market.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
125,140,155,170
,,125,140,155,170
110,120,130
,100
2 changes: 2 additions & 0 deletions test/test_market.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div style="width: max-content;">
<div style="position: relative; display: inline-block; padding: 4px; width: 40px; height: 40px; border: 1px solid rgba(0, 0, 0, 0); margin: 0px; vertical-align: top;"></div>
<div style="position: relative; display: inline-block; padding: 4px; width: 40px; height: 40px; border: 1px solid rgba(0, 0, 0, 0); margin: 0px; vertical-align: top;"></div>
<div style="position: relative; display: inline-block; padding: 4px; width: 40px; height: 40px; border: 1px solid rgba(0, 0, 0, 0.2); margin: 0px; vertical-align: top; color: rgb(0, 0, 0); background-color: rgb(211, 211, 211);">
<div class="xsmall_font">125</div>
<div></div>
Expand Down
4 changes: 2 additions & 2 deletions test/test_importer.py → test/test_market_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from pandas import DataFrame
from numpy import nan

from importer import import_csv_market, import_html_market
from market_import import import_csv_market, import_html_market

class TestImporter(unittest.TestCase):
MARKET_CSV_PATH = 'test_market.csv'
MARKET_HTML_PATH = 'test_market.html'
MARKET = DataFrame([
[125, 140, 155, 170],
[nan, nan, 125, 140, 155, 170],
[110, 120, 130],
[nan, 100]
])
Expand Down

0 comments on commit 8071058

Please sign in to comment.