diff options
| -rw-r--r-- | .gitattributes | 5 | ||||
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | GlobalLandTemperaturesByCity.csv | 3 | ||||
| -rw-r--r-- | __pycache__/decompressor.cpython-38.pyc | bin | 0 -> 601 bytes | |||
| -rw-r--r-- | arima_predictor.py | 3 | ||||
| -rw-r--r-- | database.db | 3 | ||||
| -rw-r--r-- | decompressor.py | 15 | ||||
| -rw-r--r-- | time_series_model.py | 13 | ||||
| -rw-r--r-- | zipper.py | 14 |
9 files changed, 51 insertions, 8 deletions
diff --git a/.gitattributes b/.gitattributes index 81a7c83..fee1c45 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ -*.db filter=lfs diff=lfs merge=lfs -text -*.csv filter=lfs diff=lfs merge=lfs -text +# *.db filter=lfs diff=lfs merge=lfs -text +# *.csv filter=lfs diff=lfs merge=lfs -text +# *.compressed filter=lfs diff=lfs merge=lfs -text @@ -1 +1,4 @@ .DS_Store +arima* +database.db +GlobalLandTemperaturesByCity.csv diff --git a/GlobalLandTemperaturesByCity.csv b/GlobalLandTemperaturesByCity.csv deleted file mode 100644 index b980b00..0000000 --- a/GlobalLandTemperaturesByCity.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9be86b51487f10e811a0ab43a75946739dfe7bea2342ddcd1f6bc48d51b8c493 -size 532830464 diff --git a/__pycache__/decompressor.cpython-38.pyc b/__pycache__/decompressor.cpython-38.pyc Binary files differnew file mode 100644 index 0000000..9c96491 --- /dev/null +++ b/__pycache__/decompressor.cpython-38.pyc diff --git a/arima_predictor.py b/arima_predictor.py index f6d574f..1b38a0f 100644 --- a/arima_predictor.py +++ b/arima_predictor.py @@ -1,6 +1,9 @@ import pandas as pd import matplotlib.pyplot as plt import pickle +from decompressor import decompress_arima + +decompress_arima() with open('arima.pkl', 'rb') as pkl: n_periods = 30 diff --git a/database.db b/database.db deleted file mode 100644 index 055da59..0000000 --- a/database.db +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:4e543fc52dfaba299c76e4eaf8451a1291487ac2af315cc600975d244cbb7e5b -size 156913664 diff --git a/decompressor.py b/decompressor.py new file mode 100644 index 0000000..c54dec9 --- /dev/null +++ b/decompressor.py @@ -0,0 +1,15 @@ +from os.path import exists +import zlib + +def decompress_arima(): + if not exists('arima.pkl'): + if not exists('arima.compressed'): + raise FileNotFoundError('arima.compressed not found') + else: + print('Decompressing arima.compressed') + with open('arima.compressed', 'rb') as f: + data = zlib.decompress(f.read()) + with open('arima.pkl', 'wb') as f: + f.write(data) + +decompress_arima()
\ No newline at end of file diff --git a/time_series_model.py b/time_series_model.py index 3fca7c0..15b8dce 100644 --- a/time_series_model.py +++ b/time_series_model.py @@ -2,6 +2,9 @@ import pandas as pd from sql_functions import execute_sql_statement import pmdarima as pm import pickle +import zlib +from os.path import exists +from os import remove sql_stmt = "select date, city_id, cast(avg_temperature as real) as temp from temperature where date is not null and temp is not null" @@ -24,3 +27,13 @@ ts_model = pm.auto_arima(data.temp, start_p=1, start_q=1, with open('arima.pkl', 'wb') as pkl: pickle.dump(ts_model, pkl) + +filename_in = "arima.pkl" +filename_out = "arima.compressed" +if exists(filename_out): + remove(filename_out) +with open(filename_in, mode="rb") as fin, open(filename_out, mode="wb") as fout: + data = fin.read() + print("Compressing Pickle File for Version Control...") + compressed_data = zlib.compress(data, zlib.Z_BEST_COMPRESSION) + fout.write(compressed_data) diff --git a/zipper.py b/zipper.py new file mode 100644 index 0000000..bc5ada7 --- /dev/null +++ b/zipper.py @@ -0,0 +1,14 @@ +import zlib +from os.path import exists +from os import remove + + +filename_in = "arima.pkl" +filename_out = "arima.compressed" +if exists(filename_out): + remove(filename_out) +with open(filename_in, mode="rb") as fin, open(filename_out, mode="wb") as fout: + data = fin.read() + print("Compressing Pickle File for Version Control...") + compressed_data = zlib.compress(data, zlib.Z_BEST_COMPRESSION) + fout.write(compressed_data)
\ No newline at end of file |
