File size: 3,898 Bytes
43106f9
 
 
 
1030c11
f2e3576
1030c11
f2e3576
 
 
 
 
 
 
 
 
 
1030c11
f2e3576
 
 
 
 
 
 
 
 
1030c11
f2e3576
1030c11
f2e3576
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1030c11
f2e3576
1030c11
f2e3576
1030c11
f2e3576
 
 
 
 
 
43106f9
f2e3576
 
 
 
 
 
 
 
 
43106f9
 
 
f2e3576
 
 
 
 
43106f9
f2e3576
 
 
 
 
 
 
 
 
 
43106f9
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import random\n",
    "import os \n",
    "import hopsworks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Connected. Call `.close()` to terminate connection gracefully.\n",
      "\n",
      "Logged in to project, explore it here https://c.app.hopsworks.ai:443/p/1160340\n",
      "2024-11-20 03:57:50,799 WARNING: using legacy validation callback\n",
      "Connected. Call `.close()` to terminate connection gracefully.\n",
      "Finished: Reading data from Hopsworks, using Hopsworks Feature Query Service (1.82s) \n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1589 entries, 0 to 1588\n",
      "Data columns (total 6 columns):\n",
      " #   Column   Non-Null Count  Dtype  \n",
      "---  ------   --------------  -----  \n",
      " 0   date     1589 non-null   object \n",
      " 1   pm25     1589 non-null   float32\n",
      " 2   country  1589 non-null   object \n",
      " 3   city     1589 non-null   object \n",
      " 4   street   1589 non-null   object \n",
      " 5   url      1589 non-null   object \n",
      "dtypes: float32(1), object(5)\n",
      "memory usage: 68.4+ KB\n",
      "None\n",
      "         date  pm25 country         city          street  \\\n",
      "0  2024-02-23  18.0  Sweden  Helsingborg  Drottninggatan   \n",
      "1  2021-09-22  36.0  Sweden  Helsingborg  Drottninggatan   \n",
      "2  2022-09-25  55.0  Sweden  Helsingborg  Drottninggatan   \n",
      "3  2024-08-25  24.0  Sweden  Helsingborg  Drottninggatan   \n",
      "4  2023-01-06  18.0  Sweden  Helsingborg  Drottninggatan   \n",
      "\n",
      "                                  url  \n",
      "0  https://api.waqi.info/feed/@12519/  \n",
      "1  https://api.waqi.info/feed/@12519/  \n",
      "2  https://api.waqi.info/feed/@12519/  \n",
      "3  https://api.waqi.info/feed/@12519/  \n",
      "4  https://api.waqi.info/feed/@12519/  \n"
     ]
    }
   ],
   "source": [
    "\n",
    "from datetime import datetime, timedelta\n",
    "now = datetime.now()\n",
    "\n",
    "api_key = os.getenv('HOPSWORKS_API_KEY')\n",
    "project_name = os.getenv('HOPSWORKS_PROJECT')\n",
    "\n",
    "project = hopsworks.login(project=project_name, api_key_value=api_key)\n",
    "fs = project.get_feature_store() \n",
    "\n",
    "air_quality_fg = fs.get_feature_group(\n",
    "    name='air_quality',\n",
    "    version=1,\n",
    ")\n",
    "air_quality_df = air_quality_fg.read()\n",
    "air_quality_df\n",
    "\n",
    "print(air_quality_df.info())\n",
    "print(air_quality_df.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "air_quality_df[['date', 'pm25']].to_pickle('air_quality_df.pkl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "with gr.Blocks() as demo:\n",
    "    gr.Markdown(\"Helsingborg Air Quality Forecast\")\n",
    "    gr.LinePlot(air_quality_df, x=\"time\", y=\"price\")\n",
    "    gr.ScatterPlot(air_quality_df['pm25'], x=\"time\", y=\"price\", color=\"origin\")\n",
    "\n",
    "demo.launch()   "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}