You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The 2-letter country code (e.g., "DE" for Germany, "FR" for France, etc.).
47
+
:param datetime start_time:
48
+
The start date for data retrieval (rounded to the nearest hour).
49
+
:param datetime end_time:
50
+
The end date for data retrieval (rounded to the nearest hour).
51
+
:param str type:
52
+
The type of data to retrieve; either 'generation' or 'forecast'. Defaults to 'generation'.
53
+
54
+
:return: A dictionary containing the following keys:
55
+
56
+
- **error** (*str*): An error message, empty if no errors occurred.
57
+
- **data_available** (*bool*): Indicates whether data was successfully retrieved.
58
+
- **data** (*pandas.DataFrame*): The retrieved energy data if available; an empty DataFrame otherwise.
59
+
- **time_interval** (*int*): The time interval of the DataFrame (constant value: ``60``).
60
+
- **source** (*str*): Specifies the origin of the retrieved data. Defaults to ``'public_data'``, indicating it was fetched from an external source. If the offline storage feature is enabled, this value may change if the data is available locally.
61
+
- **columns** : a dict of columns for renewable and non renewable energy sources in the data
62
+
60
63
:rtype: dict
64
+
65
+
**Example Usage:**
66
+
67
+
Get generation data for Germany
68
+
69
+
.. code-block:: python
70
+
71
+
from datetime import datetime
72
+
from codegreen_core.data import energy
73
+
result = energy(country="DE", start_time=datetime(2025, 1, 1), end_time=datetime(2025, 1, 2), type="generation")
74
+
75
+
Get forecast data for Norway
76
+
77
+
.. code-block:: python
78
+
79
+
from datetime import datetime
80
+
from codegreen_core.data import energy
81
+
result = energy(country="NO", start_time=datetime(2025, 1, 1), end_time=datetime(2025, 1, 2), type="forecast")
Data is stored in 2 sources : one. Redis cache and second : csv files.
250
-
Redis cache contains data only for the last 72 hours from when it was last synced
251
-
Offline data files can contain data for longer durations.
252
-
Both these options can be configured in the config file
253
-
returns {available:True/False, data:dataframe}
254
-
Note that this method assumes that syncing of the sources is being handled separately
248
+
This method returns locally stored energy data.
249
+
250
+
Data is stored in two sources:
251
+
252
+
1. **Redis cache**: Contains data for a limited number of hours from the last sync.
253
+
2. **CSV files**: Contain data for longer durations.
254
+
255
+
Both storage options can be configured in the configuration file.
256
+
257
+
**Note**: Unless you specify the ``sync_first`` flag, the method assumes that syncing of the data sources is handled separately. If ``sync_first`` is set to ``True`` and data files are not initialized in advance, the method may take longer to complete
258
+
259
+
:return: A dictionary with the following keys:
260
+
- **available** (*bool*): Indicates if the data is available.
261
+
- **data** (*pandas.DataFrame*): The energy data, if available. Otherwise, an empty DataFrame.
This method syncs offline data for offline sources enabled in the cache.
296
-
Data is synced for all available countries
297
-
You need to run this before getting offline data. you can even setup a CRON job to call this method on regular intervals
306
+
This method syncs offline data for offline sources enabled in the configuration file. The data is synced for all available countries.
307
+
308
+
You need to run this method before retrieving offline data. It is also possible to set up a CRON job to call this method at regular intervals to keep data synchronized.
309
+
310
+
The sync operation can take some time, depending on the data size and the selected sync options (file, cache, or both).
311
+
312
+
:param bool file: If ``True``, sync data in offline files. Defaults to ``False``.
313
+
:param bool cache: If ``True``, sync data in the cache. Defaults to ``False``.
0 commit comments