From f34b8db3751ddacc64c7da3bf36e099c98139cfd Mon Sep 17 00:00:00 2001 From: toravest Date: Fri, 21 Mar 2025 11:10:39 +0100 Subject: [PATCH] add text, readme, notebook and other minor changes --- .gitignore | 4 +- data/README.md | 15 +- notebooks/get_data_notebook.ipynb | 789 +++++++++++++++++------------- notebooks/test_notebook.ipynb | 6 +- src/my_package/fetch_data.py | 5 +- tests/unit/test_test.py | 2 +- 6 files changed, 459 insertions(+), 362 deletions(-) diff --git a/.gitignore b/.gitignore index 3cd0510..701031c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ /__pycache__/ *.pyc /venv/ -.env \ No newline at end of file +.env +/data/output*/ +old_* \ No newline at end of file diff --git a/data/README.md b/data/README.md index 1612d3a..401b18a 100644 --- a/data/README.md +++ b/data/README.md @@ -1,8 +1,13 @@ -# Data-description +# Data-description -API from openweathermap -[API](https://openweathermap.org/) +### Possible API +- **API from openweathermap** +[API_OPEN_WEATHER_MAP](https://openweathermap.org/) -Possible dataset - Natural Disasters: -[Dataset 1](https://www.kaggle.com/datasets/brsdincer/all-natural-disasters-19002021-eosdis) +- **API from meterologisk institutt** +[API_FROST](https://frost.met.no/index.html) + +### Possible dataset +- **Natural Disasters:** +[DATASET_1](https://www.kaggle.com/datasets/brsdincer/all-natural-disasters-19002021-eosdis) diff --git a/notebooks/get_data_notebook.ipynb b/notebooks/get_data_notebook.ipynb index f544ff7..c3b6ad0 100644 --- a/notebooks/get_data_notebook.ipynb +++ b/notebooks/get_data_notebook.ipynb @@ -10,28 +10,30 @@ "\n", "Dataen skrives inn slik: (yyyy, mm, dd, hh, mm)\n", "Her følger et eksempel: \n", - "yyyy = 2025 # år \n", - "mm = 03 # måned \n", - "dd = 01 # dato \n", - "hh = 12 # time \n", - "mm = 00 # minutt \n", + "|Hva|Hvordan|Eksempel|\n", + "|:---|:---:|:---:|\n", + "|år|yyyy|2025|\n", + "|måned|mm|03| \n", + "|dato|dd|01| \n", + "|time|hh|12| \n", + "|minutt|mm|00| \n", "\n", "Denne dataen skrives da inn på følgende hvis: (2025, 03, 01, 12, 00)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Start date => unix timestamp: 1735686000\n", - "End date => unix timestamp: 1735772340\n", - "Unix timestamp => start date: 2025-01-01 00:00:00\n", - "Unix timestamp => end date: 2025-01-01 23:59:00\n" + "Start date => unix timestamp: 1742202600\n", + "End date => unix timestamp: 1742548200\n", + "Unix timestamp => start date: 2025-03-17 10:10:00\n", + "Unix timestamp => end date: 2025-03-21 10:10:00\n" ] } ], @@ -65,7 +67,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Velg en sted i Norge og få data\n", + "### Velg et sted i Norge og få data\n", "\n", "Skriv inn et sted du ønsker data fra, foreløpig er det begrenset til Norge\n", "\n", @@ -74,364 +76,451 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Data has been written to /Users/toravestlund/Documents/ITBAITBEDR/TDT4114 - Anvendt programmering/anvendt_mappe/data/json/data_Jorpeland.json\n" + "Data fetch: ok\n" ] - }, + } + ], + "source": [ + "import sys\n", + "import os\n", + "\n", + "# Gets the absolute path to the src folder\n", + "sys.path.append(os.path.abspath(\"../src\"))\n", + "\n", + "# Now we can import the fucntion from the module\n", + "from my_package.fetch_data import fetch_data\n", + "\n", + "# User input the city, for the weather\n", + "city_name = input(\"Enter a city in Norway: \")\n", + "\n", + "data = fetch_data(unix_start_date, unix_end_date, city_name)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Lagre data i en json-fil\n", + "\n", + "Skriv inn navn for til filen du vil lagre med dataen.\n", + "\n", + "Eks. test\n", + "Da vil filen lagres som data_**test**.json, i mappen \"../data/output_stedsnavn/data_{filnavn}.json\"\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Data has been written to /Users/toravestlund/Documents/ITBAITBEDR/TDT4114 - Anvendt programmering/anvendt_mappe/data/output_stedsdata/data_test6.json\n" + ] + } + ], + "source": [ + "# Gets the absolute path to the src folder\n", + "sys.path.append(os.path.abspath(\"../src\"))\n", + "\n", + "from my_package.write_data import write_data\n", + "\n", + "filename = input(\"Write filename: \")\n", + "\n", + "write_data(data, filename)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Lese fra fil\n", + "\n", + "Henter opp data lagret i filen, lagd over, og skriver ut lesbart ved hjelp av pandas" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " message cod city_id calctime cnt \\\n", + "0 Count: 96 200 3133880 0.021173 96 \n", + "1 Count: 96 200 3133880 0.021173 96 \n", + "2 Count: 96 200 3133880 0.021173 96 \n", + "3 Count: 96 200 3133880 0.021173 96 \n", + "4 Count: 96 200 3133880 0.021173 96 \n", + ".. ... ... ... ... ... \n", + "91 Count: 96 200 3133880 0.021173 96 \n", + "92 Count: 96 200 3133880 0.021173 96 \n", + "93 Count: 96 200 3133880 0.021173 96 \n", + "94 Count: 96 200 3133880 0.021173 96 \n", + "95 Count: 96 200 3133880 0.021173 96 \n", + "\n", + " list \n", + "0 {'dt': 1742205600, 'main': {'temp': 1.98, 'fee... \n", + "1 {'dt': 1742209200, 'main': {'temp': 3.05, 'fee... \n", + "2 {'dt': 1742212800, 'main': {'temp': 3.6, 'feel... \n", + "3 {'dt': 1742216400, 'main': {'temp': 4.16, 'fee... \n", + "4 {'dt': 1742220000, 'main': {'temp': 4.11, 'fee... \n", + ".. ... \n", + "91 {'dt': 1742533200, 'main': {'temp': -0.24, 'fe... \n", + "92 {'dt': 1742536800, 'main': {'temp': -0.24, 'fe... \n", + "93 {'dt': 1742540400, 'main': {'temp': 0.62, 'fee... \n", + "94 {'dt': 1742544000, 'main': {'temp': 2.18, 'fee... \n", + "95 {'dt': 1742547600, 'main': {'temp': 5.03, 'fee... \n", + "\n", + "[96 rows x 6 columns]\n" + ] + } + ], + "source": [ + "import pandas as pd\n", + "\n", + "data = pd.read_json(f'../data/output_stedsdata/data_{filename}.json')\n", + "\n", + "print(data)" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ { "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
main.tempmain.feels_likemain.pressuremain.humiditymain.temp_minmain.temp_maxwind.speedwind.degwind.gustclouds.allrain.1h
dt
2025-03-17 10:00:001.980.111021921.072.771.792033.581000.36
2025-03-17 11:00:003.050.841021932.733.332.242255.361000.79
2025-03-17 12:00:003.601.491021913.033.882.242484.021001.38
2025-03-17 13:00:004.161.751021923.844.442.682708.051000.16
2025-03-17 14:00:004.110.751021893.885.034.022938.051000.14
....................................
2025-03-21 05:00:00-0.24-2.29102491-1.160.551.671221.8642NaN
2025-03-21 06:00:00-0.24-2.14102490-1.160.551.571361.6744NaN
2025-03-21 07:00:000.62-0.97102589-0.602.031.451251.7797NaN
2025-03-21 08:00:002.180.781025922.183.031.47941.9988NaN
2025-03-21 09:00:005.033.851025785.035.031.60852.2967NaN
\n", + "

96 rows × 11 columns

\n", + "
" + ], "text/plain": [ - "{'message': 'Count: 24',\n", - " 'cod': '200',\n", - " 'city_id': 3150742,\n", - " 'calctime': 0.018029492,\n", - " 'cnt': 24,\n", - " 'list': [{'dt': 1735686000,\n", - " 'main': {'temp': 8,\n", - " 'feels_like': 4,\n", - " 'pressure': 989,\n", - " 'humidity': 98,\n", - " 'temp_min': 7.75,\n", - " 'temp_max': 8.95},\n", - " 'wind': {'speed': 8.27, 'deg': 219, 'gust': 13.12},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 501,\n", - " 'main': 'Rain',\n", - " 'description': 'moderate rain',\n", - " 'icon': '10n'}],\n", - " 'rain': {'1h': 1.54}},\n", - " {'dt': 1735689600,\n", - " 'main': {'temp': 8,\n", - " 'feels_like': 4.84,\n", - " 'pressure': 989,\n", - " 'humidity': 98,\n", - " 'temp_min': 7.75,\n", - " 'temp_max': 8.95},\n", - " 'wind': {'speed': 5.63, 'deg': 225, 'gust': 8.54},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04n'}]},\n", - " {'dt': 1735693200,\n", - " 'main': {'temp': 7.74,\n", - " 'feels_like': 4.16,\n", - " 'pressure': 989,\n", - " 'humidity': 97,\n", - " 'temp_min': 7.19,\n", - " 'temp_max': 8.9},\n", - " 'wind': {'speed': 6.61, 'deg': 222, 'gust': 11.2},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 500,\n", - " 'main': 'Rain',\n", - " 'description': 'light rain',\n", - " 'icon': '10n'}],\n", - " 'rain': {'1h': 0.19}},\n", - " {'dt': 1735696800,\n", - " 'main': {'temp': 6.33,\n", - " 'feels_like': 2.8,\n", - " 'pressure': 988,\n", - " 'humidity': 97,\n", - " 'temp_min': 6.08,\n", - " 'temp_max': 6.9},\n", - " 'wind': {'speed': 5.47, 'deg': 234, 'gust': 8.53},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 501,\n", - " 'main': 'Rain',\n", - " 'description': 'moderate rain',\n", - " 'icon': '10n'}],\n", - " 'rain': {'1h': 2.73}},\n", - " {'dt': 1735700400,\n", - " 'main': {'temp': 6.33,\n", - " 'feels_like': 3.35,\n", - " 'pressure': 987,\n", - " 'humidity': 97,\n", - " 'temp_min': 6.08,\n", - " 'temp_max': 7.28},\n", - " 'wind': {'speed': 4.27, 'deg': 225, 'gust': 8.17},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04n'}]},\n", - " {'dt': 1735704000,\n", - " 'main': {'temp': 5.42,\n", - " 'feels_like': 2.52,\n", - " 'pressure': 987,\n", - " 'humidity': 99,\n", - " 'temp_min': 5.41,\n", - " 'temp_max': 7.28},\n", - " 'wind': {'speed': 3.75, 'deg': 248, 'gust': 7.09},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 500,\n", - " 'main': 'Rain',\n", - " 'description': 'light rain',\n", - " 'icon': '10n'}],\n", - " 'rain': {'1h': 1}},\n", - " {'dt': 1735707600,\n", - " 'main': {'temp': 4.31,\n", - " 'feels_like': 1.6,\n", - " 'pressure': 986,\n", - " 'humidity': 99,\n", - " 'temp_min': 4.29,\n", - " 'temp_max': 6.17},\n", - " 'wind': {'speed': 3.11, 'deg': 274, 'gust': 3.57},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 500,\n", - " 'main': 'Rain',\n", - " 'description': 'light rain',\n", - " 'icon': '10n'}],\n", - " 'rain': {'1h': 0.61}},\n", - " {'dt': 1735711200,\n", - " 'main': {'temp': 3.31,\n", - " 'feels_like': 0.37,\n", - " 'pressure': 987,\n", - " 'humidity': 97,\n", - " 'temp_min': 2.75,\n", - " 'temp_max': 5.06},\n", - " 'wind': {'speed': 3.14, 'deg': 288, 'gust': 3.4},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 500,\n", - " 'main': 'Rain',\n", - " 'description': 'light rain',\n", - " 'icon': '10n'}],\n", - " 'rain': {'1h': 0.56}},\n", - " {'dt': 1735714800,\n", - " 'main': {'temp': 3,\n", - " 'feels_like': -0.12,\n", - " 'pressure': 987,\n", - " 'humidity': 97,\n", - " 'temp_min': 2.75,\n", - " 'temp_max': 3.95},\n", - " 'wind': {'speed': 3.29, 'deg': 289, 'gust': 3.54},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 500,\n", - " 'main': 'Rain',\n", - " 'description': 'light rain',\n", - " 'icon': '10n'}],\n", - " 'rain': {'1h': 0.14}},\n", - " {'dt': 1735718400,\n", - " 'main': {'temp': 2.75,\n", - " 'feels_like': -0.07,\n", - " 'pressure': 987,\n", - " 'humidity': 97,\n", - " 'temp_min': 2.19,\n", - " 'temp_max': 3.95},\n", - " 'wind': {'speed': 2.84, 'deg': 265, 'gust': 3.28},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04n'}],\n", - " 'rain': {'1h': 0.1}},\n", - " {'dt': 1735722000,\n", - " 'main': {'temp': 2.74,\n", - " 'feels_like': -0.21,\n", - " 'pressure': 987,\n", - " 'humidity': 96,\n", - " 'temp_min': 2.19,\n", - " 'temp_max': 3.39},\n", - " 'wind': {'speed': 3, 'deg': 279, 'gust': 3.26},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04d'}]},\n", - " {'dt': 1735725600,\n", - " 'main': {'temp': 2.14,\n", - " 'feels_like': -1.38,\n", - " 'pressure': 987,\n", - " 'humidity': 96,\n", - " 'temp_min': 1.64,\n", - " 'temp_max': 2.9},\n", - " 'wind': {'speed': 3.59, 'deg': 274, 'gust': 3.72},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04d'}]},\n", - " {'dt': 1735729200,\n", - " 'main': {'temp': 1.9,\n", - " 'feels_like': -1.5,\n", - " 'pressure': 987,\n", - " 'humidity': 95,\n", - " 'temp_min': 1.64,\n", - " 'temp_max': 2.9},\n", - " 'wind': {'speed': 3.36, 'deg': 277, 'gust': 3.38},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04d'}]},\n", - " {'dt': 1735732800,\n", - " 'main': {'temp': 1.89,\n", - " 'feels_like': -1.23,\n", - " 'pressure': 988,\n", - " 'humidity': 94,\n", - " 'temp_min': 1.09,\n", - " 'temp_max': 2.84},\n", - " 'wind': {'speed': 3, 'deg': 283, 'gust': 2.94},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04d'}]},\n", - " {'dt': 1735736400,\n", - " 'main': {'temp': 1.34,\n", - " 'feels_like': -1.72,\n", - " 'pressure': 988,\n", - " 'humidity': 94,\n", - " 'temp_min': 1.08,\n", - " 'temp_max': 2.28},\n", - " 'wind': {'speed': 2.8, 'deg': 282, 'gust': 2.69},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04d'}]},\n", - " {'dt': 1735740000,\n", - " 'main': {'temp': 0.78,\n", - " 'feels_like': -2.15,\n", - " 'pressure': 988,\n", - " 'humidity': 95,\n", - " 'temp_min': 0.53,\n", - " 'temp_max': 1.73},\n", - " 'wind': {'speed': 2.55, 'deg': 298, 'gust': 2.5},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04d'}]},\n", - " {'dt': 1735743600,\n", - " 'main': {'temp': 0.77,\n", - " 'feels_like': -2.55,\n", - " 'pressure': 989,\n", - " 'humidity': 95,\n", - " 'temp_min': -0.03,\n", - " 'temp_max': 1.73},\n", - " 'wind': {'speed': 2.97, 'deg': 327, 'gust': 3.1},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04n'}]},\n", - " {'dt': 1735747200,\n", - " 'main': {'temp': 0.24,\n", - " 'feels_like': -4.09,\n", - " 'pressure': 990,\n", - " 'humidity': 95,\n", - " 'temp_min': -0.03,\n", - " 'temp_max': 1.33},\n", - " 'wind': {'speed': 4.15, 'deg': 334, 'gust': 4.35},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 600,\n", - " 'main': 'Snow',\n", - " 'description': 'light snow',\n", - " 'icon': '13n'}],\n", - " 'snow': {'1h': 0.32}},\n", - " {'dt': 1735750800,\n", - " 'main': {'temp': 0.23,\n", - " 'feels_like': -4.73,\n", - " 'pressure': 991,\n", - " 'humidity': 95,\n", - " 'temp_min': -0.58,\n", - " 'temp_max': 1.17},\n", - " 'wind': {'speed': 5.18, 'deg': 340, 'gust': 4.9},\n", - " 'clouds': {'all': 100},\n", - " 'weather': [{'id': 600,\n", - " 'main': 'Snow',\n", - " 'description': 'light snow',\n", - " 'icon': '13n'}],\n", - " 'snow': {'1h': 0.25}},\n", - " {'dt': 1735754400,\n", - " 'main': {'temp': 0.22,\n", - " 'feels_like': -4.84,\n", - " 'pressure': 993,\n", - " 'humidity': 93,\n", - " 'temp_min': -0.1,\n", - " 'temp_max': 1.17},\n", - " 'wind': {'speed': 5.35, 'deg': 347, 'gust': 5.68},\n", - " 'clouds': {'all': 99},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04n'}]},\n", - " {'dt': 1735758000,\n", - " 'main': {'temp': -0.03,\n", - " 'feels_like': -4.98,\n", - " 'pressure': 994,\n", - " 'humidity': 92,\n", - " 'temp_min': -0.59,\n", - " 'temp_max': 0.61},\n", - " 'wind': {'speed': 5.04, 'deg': 1, 'gust': 5.74},\n", - " 'clouds': {'all': 95},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04n'}]},\n", - " {'dt': 1735761600,\n", - " 'main': {'temp': -0.34,\n", - " 'feels_like': -4.67,\n", - " 'pressure': 995,\n", - " 'humidity': 91,\n", - " 'temp_min': -1.14,\n", - " 'temp_max': 0.06},\n", - " 'wind': {'speed': 3.96, 'deg': 20, 'gust': 4.67},\n", - " 'clouds': {'all': 89},\n", - " 'weather': [{'id': 804,\n", - " 'main': 'Clouds',\n", - " 'description': 'overcast clouds',\n", - " 'icon': '04n'}]},\n", - " {'dt': 1735765200,\n", - " 'main': {'temp': -0.35,\n", - " 'feels_like': -4.09,\n", - " 'pressure': 996,\n", - " 'humidity': 90,\n", - " 'temp_min': -0.89,\n", - " 'temp_max': -0.1},\n", - " 'wind': {'speed': 3.19, 'deg': 16, 'gust': 3.98},\n", - " 'clouds': {'all': 62},\n", - " 'weather': [{'id': 803,\n", - " 'main': 'Clouds',\n", - " 'description': 'broken clouds',\n", - " 'icon': '04n'}]},\n", - " {'dt': 1735768800,\n", - " 'main': {'temp': -0.89,\n", - " 'feels_like': -4.8,\n", - " 'pressure': 997,\n", - " 'humidity': 87,\n", - " 'temp_min': -1.69,\n", - " 'temp_max': -0.1},\n", - " 'wind': {'speed': 3.26, 'deg': 19, 'gust': 3.75},\n", - " 'clouds': {'all': 49},\n", - " 'weather': [{'id': 802,\n", - " 'main': 'Clouds',\n", - " 'description': 'scattered clouds',\n", - " 'icon': '03n'}]}]}" + " main.temp main.feels_like main.pressure main.humidity \\\n", + "dt \n", + "2025-03-17 10:00:00 1.98 0.11 1021 92 \n", + "2025-03-17 11:00:00 3.05 0.84 1021 93 \n", + "2025-03-17 12:00:00 3.60 1.49 1021 91 \n", + "2025-03-17 13:00:00 4.16 1.75 1021 92 \n", + "2025-03-17 14:00:00 4.11 0.75 1021 89 \n", + "... ... ... ... ... \n", + "2025-03-21 05:00:00 -0.24 -2.29 1024 91 \n", + "2025-03-21 06:00:00 -0.24 -2.14 1024 90 \n", + "2025-03-21 07:00:00 0.62 -0.97 1025 89 \n", + "2025-03-21 08:00:00 2.18 0.78 1025 92 \n", + "2025-03-21 09:00:00 5.03 3.85 1025 78 \n", + "\n", + " main.temp_min main.temp_max wind.speed wind.deg \\\n", + "dt \n", + "2025-03-17 10:00:00 1.07 2.77 1.79 203 \n", + "2025-03-17 11:00:00 2.73 3.33 2.24 225 \n", + "2025-03-17 12:00:00 3.03 3.88 2.24 248 \n", + "2025-03-17 13:00:00 3.84 4.44 2.68 270 \n", + "2025-03-17 14:00:00 3.88 5.03 4.02 293 \n", + "... ... ... ... ... \n", + "2025-03-21 05:00:00 -1.16 0.55 1.67 122 \n", + "2025-03-21 06:00:00 -1.16 0.55 1.57 136 \n", + "2025-03-21 07:00:00 -0.60 2.03 1.45 125 \n", + "2025-03-21 08:00:00 2.18 3.03 1.47 94 \n", + "2025-03-21 09:00:00 5.03 5.03 1.60 85 \n", + "\n", + " wind.gust clouds.all rain.1h \n", + "dt \n", + "2025-03-17 10:00:00 3.58 100 0.36 \n", + "2025-03-17 11:00:00 5.36 100 0.79 \n", + "2025-03-17 12:00:00 4.02 100 1.38 \n", + "2025-03-17 13:00:00 8.05 100 0.16 \n", + "2025-03-17 14:00:00 8.05 100 0.14 \n", + "... ... ... ... \n", + "2025-03-21 05:00:00 1.86 42 NaN \n", + "2025-03-21 06:00:00 1.67 44 NaN \n", + "2025-03-21 07:00:00 1.77 97 NaN \n", + "2025-03-21 08:00:00 1.99 88 NaN \n", + "2025-03-21 09:00:00 2.29 67 NaN \n", + "\n", + "[96 rows x 11 columns]" ] }, - "execution_count": 3, "metadata": {}, - "output_type": "execute_result" + "output_type": "display_data" } ], "source": [ - "import sys\n", - "import os\n", + "import pandas as pd\n", "\n", - "# Gets the absolute path to the src folder\n", - "sys.path.append(os.path.abspath(\"../src\"))\n", + "data = pd.read_json(f'../data/output_stedsdata/data_{filename}.json')\n", "\n", - "# Now we can import the fucntion from the module\n", - "from my_package.get_data import get_data\n", + "if 'list' in data:\n", + " df = pd.json_normalize(data['list'])\n", + "\n", + " # Delete duplicates based on the dt row, all the other values can appear more than once, but the date should only appear once\n", + " df = df.drop_duplicates(subset=['dt'])\n", + "\n", + " # The weather column dosnt have any releated information, therefor we delete it\n", + " df = df.drop(columns=\"weather\")\n", + "\n", + " # Convert 'dt' column from Unix timestamp to datetime and set it as the index\n", + " df['dt'] = pd.to_datetime(df['dt'], unit='s')\n", + " df.set_index('dt', inplace=True)\n", + " \n", + "\n", + " \n", + "\n", + " # Ensure the DataFrame is displayed correctly\n", + " display(df)\n", + "\n", + " # # Extract main values\n", + " # temp = df['main.temp']\n", + " # humidity = df['main.humidity']\n", + "\n", + " # # Extract wind values\n", + " # w_speed = df['wind.speed']\n", "\n", - "get_data(unix_start_date, unix_end_date)" + " # # Extract other variables\n", + " # clouds = df['clouds.all']\n", + "\n", + " # try:\n", + " # rain = df['rain.1h']\n", + " # except KeyError:\n", + " # print(\"'Rain' is not present in the JSON file.\")\n", + "\n", + " # try:\n", + " # snow = df['snow.1h']\n", + " # except KeyError:\n", + " # print(\"'Snow' is not present in the JSON file.\")\n", + "\n", + " # # Print the average temperature\n", + " # print('Gjennomsnitts temperatur: ', temp.mean().round(2))\n", + "\n", + " # Display the temperature column\n", + " # display(temp)\n", + "else:\n", + " print(\"The 'list' key is not present in the JSON file.\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# \"komprimere oversikten over\"\n", + "# Som i å, finne gjennomsnitt av alle aktuelle data, \n", + "# høyeste, laveste (spesielt temp) i gitte periode" ] } ], diff --git a/notebooks/test_notebook.ipynb b/notebooks/test_notebook.ipynb index 68263a8..c887b20 100644 --- a/notebooks/test_notebook.ipynb +++ b/notebooks/test_notebook.ipynb @@ -2,16 +2,16 @@ "cells": [ { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'Hello world!'" + "'Hello World!'" ] }, - "execution_count": 3, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } diff --git a/src/my_package/fetch_data.py b/src/my_package/fetch_data.py index c48d9a4..edbc9bc 100644 --- a/src/my_package/fetch_data.py +++ b/src/my_package/fetch_data.py @@ -4,7 +4,7 @@ from dotenv import load_dotenv -# only for change unix to date for plot +# # only for change unix to date for plot # import matplotlib.pyplot as plt # import datetime # import time @@ -14,6 +14,7 @@ # Gets the key, from my env file API_KEY = os.getenv("API_KEY") +# city_name = "Trondheim" country_code = "NO" # Temporarily standard times @@ -44,7 +45,7 @@ def fetch_data(start_date, end_date, city_name): print("Failed to fetch data from API. Status code:", response.status_code) -# myData = get_data(start_date, end_date) +# myData = fetch_data(start_date, end_date, city_name) # if myData is not None: # # Empty dict for temperature diff --git a/tests/unit/test_test.py b/tests/unit/test_test.py index 509ca31..0c775bd 100644 --- a/tests/unit/test_test.py +++ b/tests/unit/test_test.py @@ -2,7 +2,7 @@ import sys, os # This will make the absolute path, from the working directory, so it will not work every time, if we hav 'cd' into another folder -# sys.path.append(os.path.abspath("src")) +# sys.path.append(os.path.abspath("../../src")) # This will make the absolute path from the root of the project, and will therefor work every time sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../src")))