Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
add timeseries
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Sep 24, 2016
1 parent f9b0367 commit ff6964a
Show file tree
Hide file tree
Showing 15 changed files with 2,502 additions and 382 deletions.
730 changes: 365 additions & 365 deletions _doc/notebooks/td2a/Python-Logique-SQL.ipynb

Large diffs are not rendered by default.

1,395 changes: 1,395 additions & 0 deletions _doc/notebooks/td2a/ml_timeseries_base.ipynb

Large diffs are not rendered by default.

Expand Up @@ -2,7 +2,7 @@

.. blogpost::
:title: Permutations et récursivité
:keywords:
:keywords: permutation, combinatoire
:date: 2016-09-16
:categories: TD

Expand Down
37 changes: 37 additions & 0 deletions _doc/sphinxdoc/source/blog/2016/2016-09-24_js.rst
@@ -0,0 +1,37 @@


.. blogpost::
:title: Javascript et traitement de données
:keywords:
:date: 2016-09-24
:categories: programmation, javascript
:lid: blog-js-data

Un des candidats a une forte préférence pour le Javascript
et son premier réflexe est d'utiliser ce langage très utilisé
pour tout ce qui est graphique. Comme éditeur, il utilise
`Atom <https://atom.io/>`_ que je m'empresse d'essayer à mon tour.
Il traite les données en JSON car ce format est le plus adéquat pour ce langage.
Le site `learnjsdata <http://learnjsdata.com/>`_ guide les programmeurs
vers l'utilisation du javascript pour traiter les données.
Il existe des librairies qui implémentent les dataframe
comme `jsdataframe <https://github.com/osdat/jsdataframe>`_.
Le navigateur execute le javascript excepté si un serveur est requis.
Dans ce cas, la solution est d'utiliser un plugin
`Chrome <https://www.google.com/chrome/>`_ :
`Web Server for Chrome <https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb?hl=en>`_.
`Chrome <https://www.google.com/chrome/>`_ reste le navigateur préféré des dévelopeurs.
Autre option `http-static <https://www.npmjs.com/package/http-static>`_.

Côté graph, `d3.js <https://d3js.org/>`_ reste un standard mais un peu ardu au premier abord.
Il faut regarder du côté de `c3.js <http://c3js.org/>`_
ou plus simple encore `morris.js <http://morrisjs.github.io/morris.js/>`_.
Une dernière astuce, pour des graphes plus élaborés, presque des peintures,
il faut se tourner vers `InkScape <https://inkscape.org/en/>`_ et exporter
son dessin en `SVG <https://en.wikipedia.org/wiki/Scalable_Vector_Graphics>`_.
A partir de là, on peut le retravailler avec `d3.js <https://d3js.org/>`_.
`dc.js <https://dc-js.github.io/dc.js/>`_ a l'air assez doué pour lier les graphes
entre eux et les faire interagir.



9 changes: 9 additions & 0 deletions _doc/sphinxdoc/source/notebooks/_gs2a_timseries.rst
@@ -0,0 +1,9 @@


Timeseries - Séries temporelles
===============================

.. toctree::
:maxdepth: 2

ml_timeseries_base
15 changes: 14 additions & 1 deletion _doc/sphinxdoc/source/td_2a.rst
Expand Up @@ -112,7 +112,11 @@ Les librairies les plus récentes implémentent les deux modes en cherchant touj
de simplicité. A ce sujet, il faut jeter un coup d'oeil à
`flexx <https://flexx.readthedocs.io/en/stable/>`_. Elles explorent aussi
la visualisation animée de gros jeux de données telle que
`datshader <http://www.xavierdupre.fr/app/jupytalk/helpsphinx/notebooks/big_datashader.html#bigdatashaderrst>`_.
`datashader <http://www.xavierdupre.fr/app/jupytalk/helpsphinx/notebooks/big_datashader.html#bigdatashaderrst>`_.

**Javascript**

* Lire :ref:`Javascript et traitement de données <blog-js-data>`

Cartes
++++++
Expand Down Expand Up @@ -257,6 +261,15 @@ Notion abordées :
* sérialisation : le fait de convertir n'importe quelle structure de données en un
tableau d'octets, c'est indispensable pour la communication entre deux machines,
deux processus


Timeseries - Séries temporelles
===============================

.. toctree::
:maxdepth: 2

notebooks/_gs2a_timeseries


.. _l-puzzlealgo2A:
Expand Down
90 changes: 90 additions & 0 deletions _unittests/ut_data/test_data_web.py
@@ -0,0 +1,90 @@
"""
@brief test log(time=3s)
"""

import sys
import os
import unittest
import warnings


try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src

try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyquickhelper",
"src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper as skip_

try:
import pyensae as skip__
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyensae",
"src")))
if path not in sys.path:
sys.path.append(path)
import pyensae as skip__

from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder
from src.ensae_teaching_cs.data import google_trends


class TestDataWeb(unittest.TestCase):

def test_google_trends_macron(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

temp = get_temp_folder(__file__, "temp_google_trends_macron")
text = google_trends(local=True, filename=False)
assert text is not None

name = google_trends(local=True, filename=True)
assert name.endswith("macron.csv")

try:
text2 = google_trends(
local=False, cache_folder=temp, filename=False)
except ConnectionResetError as e:
warnings.warn("Cannot check remote marathon.txt.\n" + str(e))
return

assert text2 is not None
self.assertEqual(len(text), len(text2))
self.maxDiff = None
self.assertEqual(text, text2)


if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -41,6 +41,7 @@
project_var_name + ".data.data_gutenberg": ["*.txt"],
project_var_name + ".special.data": ["*.png", "*.txt"],
project_var_name + ".data.data_1a": ["*.txt"],
project_var_name + ".data.data_web": ["*.csv"],
project_var_name + ".data.zips": ["*.zip"],
project_var_name + ".automation": ["*.xml", "*.r", "*.ico"],
project_var_name: ["rss_teachings.xml"],
Expand Down
1 change: 1 addition & 0 deletions src/ensae_teaching_cs/data/__init__.py
Expand Up @@ -5,4 +5,5 @@

from .gutenberg import gutenberg_name
from .data1a import marathon, donnees_enquete_2003_television
from .dataweb import google_trends
from .datazips import besancon_df, added
18 changes: 3 additions & 15 deletions src/ensae_teaching_cs/data/data1a.py
Expand Up @@ -2,32 +2,20 @@
@file
@brief Data mostly for the first year.
"""
import os
from .data_helper import any_local_file


def anyfile(name, local=True, cache_folder=".", filename=True):
"""
Time about marathons over cities and years
Returns any file in sub folder `data_1a <https://github.com/sdpython/ensae_teaching_cs/tree/master/src/ensae_teaching_cs/data/data_1a>`_.
@param name file to download
@param local local data or web
@param cache_folder where to cache the data if downloaded a second time
@param filename return the filename (True) or the content (False)
@return text content (str)
"""
if local:
this = os.path.abspath(os.path.dirname(__file__))
this = os.path.join(this, "data_1a", name)
if not os.path.exists(this):
raise FileNotFoundError(this)
else:
import pyensae
this = pyensae.download_data(name, whereTo=cache_folder)
if filename:
return this
else:
with open(this, "r") as f:
return f.read()
return any_local_file(name, "data_1a", cache_folder=cache_folder, filename=filename)


def marathon(local=True, cache_folder=".", filename=True):
Expand Down
31 changes: 31 additions & 0 deletions src/ensae_teaching_cs/data/data_helper.py
@@ -0,0 +1,31 @@
"""
@file
@brief Helpers to get data including in the module itself.
"""
import os


def any_local_file(name, subfolder, local=True, cache_folder=".", filename=True):
"""
Returns a local data file, reads its content or returns its content.
@param name file to download
@param subfolder sub folder
@param local local data or web
@param cache_folder where to cache the data if downloaded a second time
@param filename return the filename (True) or the content (False)
@return text content (str)
"""
if local:
this = os.path.abspath(os.path.dirname(__file__))
this = os.path.join(this, subfolder, name)
if not os.path.exists(this):
raise FileNotFoundError(this)
else:
import pyensae
this = pyensae.download_data(name, whereTo=cache_folder)
if filename:
return this
else:
with open(this, "r") as f:
return f.read()
Empty file.

0 comments on commit ff6964a

Please sign in to comment.