Commit 29eb8ea8 authored by Administrator's avatar Administrator

adding dynamic easy pie chart

parent 1646a223
{
"metadata": {
"name": "",
"signature": "sha256:9cdc6eb91e57bb2bcf7918127153694f3e13cf21edb378a1de4f0f5f19d822df"
"signature": "sha256:90c4b345528e3f03e260f9dc5da07164208f7a7daa765c42b08c93764467b531"
},
"nbformat": 3,
"nbformat_minor": 0,
......@@ -25,7 +25,7 @@
]
}
],
"prompt_number": 2
"prompt_number": 1
},
{
"cell_type": "code",
......@@ -36,7 +36,7 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
"prompt_number": 2
},
{
"cell_type": "code",
......@@ -55,7 +55,7 @@
]
}
],
"prompt_number": 4
"prompt_number": 3
},
{
"cell_type": "code",
......@@ -66,13 +66,14 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"c = gargantext.bdd.Europresse()"
"c = gargantext.bdd.Europresse()\n",
"c.add(\"/home/alexandre/projets/abeilles/documents/Europresse/html/\")"
],
"language": "python",
"metadata": {},
......@@ -83,109 +84,87 @@
"cell_type": "code",
"collapsed": false,
"input": [
"c.add(\"/home/alexandre/projets/abeilles/documents/Europresse/html_fr_test/\")"
"d = documents.models.Document()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
"prompt_number": 29
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"d = documents.models.Document()"
"for doc in c:\n",
" d = documents.models.Document()\n",
" d.project_id = \"1\"\n",
" d.corpus_id = \"1\"\n",
" d.analyst_id = \"1\"\n",
" try:\n",
" d.uniqu_id = doc[\"object_id\"]\n",
" d.date = doc[\"date\"]\n",
" d.title = doc[\"title\"]\n",
" d.authors = doc[\"authors\"]\n",
" d.text = doc[\"text\"]\n",
" d.source = doc[\"source\"]\n",
" d.save()\n",
" except:\n",
" pass"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 29
"prompt_number": 88
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"projects = documents.models.Project()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 10
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"projects.objects.all()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "Manager isn't accessible via Project instances",
"output_type": "pyerr",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-12-ef530b34c441>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprojects\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobjects\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mall\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m/home/alexandre/projets/gargantext.py/env/lib/python3.4/site-packages/django/db/models/manager.py\u001b[0m in \u001b[0;36m__get__\u001b[1;34m(self, instance, type)\u001b[0m\n\u001b[0;32m 247\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m__get__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minstance\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 248\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0minstance\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 249\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mAttributeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Manager isn't accessible via %s instances\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__name__\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 250\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmanager\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 251\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mAttributeError\u001b[0m: Manager isn't accessible via Project instances"
]
}
],
"prompt_number": 12
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"d.project_id = \"1\"\n",
"d.corpus_id = \"1\"\n",
"d.analyst_id = \"1\"\n",
"d.title = \"Notebook test\""
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 17
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"d.save()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 18
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"documents.models.Project.objects.all()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 20,
"text": [
"[<Project: Fukushima>, <Project: Bees are dying ?>]"
]
}
],
"prompt_number": 20
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x = documents.models.Document.objects.all().filter(title='sdf')"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
......@@ -194,9 +173,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"x.delete()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
......@@ -205,9 +182,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"documents.models.Document.objects.all()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
......@@ -225,53 +200,11 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"for doc in c:\n",
" d = documents.models.Document()\n",
" d.project_id = \"1\"\n",
" d.corpus_id = \"1\"\n",
" d.analyst_id = \"1\"\n",
" d.uniqu_id = doc[\"object_id\"]\n",
" d.date = doc[\"date\"]\n",
" d.title = doc[\"title\"]\n",
" d.authors = doc[\"authors\"]\n",
" d.text = doc[\"text\"]\n",
" d.source = doc[\"source\"]\n",
" d.save()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 35
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"c[0]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 32,
"text": [
"{'title': b'Gaucho : un dirigeant de Bayer chez le juge',\n",
" 'volume': 'no. 17807',\n",
" 'object_id': 'news\u00b720011109\u00b7LF\u00b7178071006',\n",
" 'authors': 'not found',\n",
" 'source': 'Le Figaro',\n",
" 'page': b'10',\n",
" 'url': '',\n",
" 'text': \"Le Figaro, no. 17807 FRANCE; SOCIETE ENVIRONNEMENT Les apiculteurs r\u00e9clament le retrait du pesticide Gaucho : un dirigeant de Bayer chez le juge Marie-Christine TABET, Yves MISEREY M\u00e9fiez-vous des abeilles ! La semaine derni\u00e8re le groupe Bayer a pris toute la mesure de l'avertissement. Le directeur g\u00e9n\u00e9ral de Bayer SA a, en effet, d\u00fb se rendre au p\u00f4le judiciaire financier chez le juge Guy Ripoll, rue des Italiens \u00e0 Paris, pour r\u00e9pondre aux questions du magistrat sur le Gaucho, un insecticide commercialis\u00e9 par la firme. Car l'Union nationale de l'apiculture fran\u00e7aise (Unaf) et plusieurs centaines d'apiculteurs en leur nom propre ont d\u00e9pos\u00e9 plainte, le 13 avril dernier, pour tromperie sur les qualit\u00e9s du produit et obtention de l'Etat d'avantages indus par fourniture de renseignements inexacts ou incomplets. En clair : escroquerie. Le bras de fer auquel se livrent apiculteurs et industriels depuis plusieurs ann\u00e9es au sujet de ce produit conna\u00eet aujourd'hui des d\u00e9veloppements judiciaires et p\u00e9naux. A l'origine ? La mortalit\u00e9 exceptionnelle des abeilles fran\u00e7aises depuis le d\u00e9but des ann\u00e9es 90. Selon les professionnels, un tiers du cheptel apicole fran\u00e7ais a disparu en quelques ann\u00e9es, mettant ainsi en p\u00e9ril l'activit\u00e9 de toute la fili\u00e8re. Pour les apiculteurs, le coupable est un \u00ab tueur en s\u00e9rie \u00bb de type phytosanitaire utilis\u00e9 massivement dans les zones de grandes cultures. Depuis ce constat, ils n'ont de cesse de demander au ministre de l'Agriculture de suspendre l'utilisation du produit \u00ab criminel \u00bb. En vain. Ils n'ont obtenu pour l'instant que la suspension de l'usage de ce produit sur le tournesol, depuis le 22 janvier 1999 et pour trois ans, alors qu'ils attendaient purement et simplement son retrait du march\u00e9. Bayer, principal producteur fran\u00e7ais de la mol\u00e9cule contenue dans le Gaucho, imidaclopride, r\u00e9cuse ces accusations. \u00ab Nous ne nions pas les probl\u00e8mes des ruchers, explique l'avocat de Bayer, Olivier Baratelli, mais les causes sont multiples et on ne peut pas d\u00e9cemment incriminer le Gaucho. \u00bb Et pour cause. La suspension de l'utilisation du Gaucho sur le seul tournesol p\u00e9nalise fortement l'entreprise, qui perd annuellement 30 MF depuis cette d\u00e9cision. Depuis 1996, les deux camps se battaient \u00e0 coups d'\u00e9tudes scientifiques et de seuils de dosage. Plus de 16 millions de francs de fonds europ\u00e9ens ont \u00e9t\u00e9 consacr\u00e9s au financement d'expertises contradictoires. Sans que chercheurs et scientifiques r\u00e9ussissent \u00e0 se mettre d'accord sur la toxicit\u00e9 r\u00e9elle ou suppos\u00e9e du Gaucho et de sa mati\u00e8re active, l'imidaclopride, sur les abeilles . Las de cette guerre des analyses, les apiculteurs ont choisi un angle d'attaque judiciaire et p\u00e9nale : la conformit\u00e9 de ce produit avec la r\u00e9glementation fran\u00e7aise et europ\u00e9enne. \u00ab Les caract\u00e9ristiques du produit d\u00e9couvertes par les laboratoires ne correspondent pas \u00e0 ce qui \u00e9tait exig\u00e9 au moment de l'obtention des autorisations de mise sur le march\u00e9, explique le conseil des apiculteurs, l'avocat Bernard Fau. Le produit est en effet pr\u00e9sent au moment de la floraison et sa r\u00e9manence dans le sol est trois ou quatre fois sup\u00e9rieure au seuil autoris\u00e9. On peut s'interroger sur les raisons de cette inad\u00e9quation. Les pouvoirs publics ont-ils dispos\u00e9 de toutes les pi\u00e8ces pour arr\u00eater leur d\u00e9cision ? \u00bb Bayer, convoqu\u00e9 comme t\u00e9moin chez le juge, en est reparti avec une longue liste de questions. \u00ab Nous avons demand\u00e9 \u00e0 \u00eatre entendus comme t\u00e9moins assist\u00e9s, confie l'avocat de Bayer, Olivier Baratelli, pour avoir acc\u00e8s au dossier. Les parties civiles n'ont pas \u00e9t\u00e9 tr\u00e8s fair-play, nous avons appris chez le magistrat qu'elles avaient \u00e9galement introduit une requ\u00eate devant le Conseil d'Etat pour obtenir au final le retrait de notre produit pour l'ensemble des cultures. \u00bb Force est de constater qu'industriels et apiculteurs sont aujourd'hui \u00e0 couteaux tir\u00e9s. Bayer a, de son c\u00f4t\u00e9, assign\u00e9 trois apiculteurs pour diffamation. Rumeurs diverses et vari\u00e9es circulent chez les adversaires : pots-de-vin, lobbying, comportements mafieux, manipulations politiques... les suspicions vont bon train. Dans les services du minist\u00e8re de l'Agriculture, on condamne \u00ab la nervosit\u00e9 et la passion \u00bb qui animent leurs interlocuteurs : \u00ab Nous avons re\u00e7u plus de 150 courriers parlementaires sur le sujet. \u00bb Les services de l'Etat doivent reconduire \u00e0 la fin de l'ann\u00e9e les homologations de mise sur le march\u00e9. Seront-ils \u00e0 leur tour convoqu\u00e9s chez le juge d'ici l\u00e0 ? Pour l'instant, le minist\u00e8re de l'Agriculture ne dispose gu\u00e8re d'\u00e9l\u00e9ments nouveaux sur le dossier, hormis une \u00e9tude multifactorielle boycott\u00e9e par l'ensemble des syndicats apicoles dont les premiers r\u00e9sultats ne devraient pas \u00eatre connus avant 2003. M\u00e9fiez-vous des abeilles . M.-C. T. Encadr\u00e9(s) : Des expertises, pas de conclusions... \u00ab Trois ann\u00e9es d'\u00e9tudes pluridisciplinaires conduites par divers organismes publics, techniques ou priv\u00e9s, n'ont pas permis aux autorit\u00e9s de conclure si le Gaucho \u00e9tait l'ennemi des abeilles \u00bb, constate Minh H\u00e0 Pham Del\u00e8gue, directrice de recherche \u00e0 l'Institut national de la recherche agricole (Inra), dans le dernier num\u00e9ro de La Recherche. Au train o\u00f9 vont les choses, on peut se demander si la spirale de l'expertise s'arr\u00eatera un jour. C'est f\u00e2cheux. Car, en France, les abeilles p\u00e9rissent en grand nombre dans des zones o\u00f9 le Gaucho n'est pas \u00e9pandu. Le varroa, un acarien parasite d'origine sib\u00e9rienne arriv\u00e9 en France en 1982 et ayant envahi l'ensemble du pays cinq ans plus tard, fait des ravages consid\u00e9rables sur de nombreuses ruches. Mais ce n'est pas le seul ennemi. \u00ab Les abeilles souffrent surtout d'une interaction entre les pathog\u00e8nes et les pesticides \u00bb, constate Yves Le Conte, directeur de recherche \u00e0 l'Inra (Avignon). Et elles ne jouissent pas de l'attention dont elles b\u00e9n\u00e9ficient en Europe centrale. Or ces petits insectes sont tr\u00e8s fragiles : il suffit qu'un agriculteur \u00e9pande un insecticide toxique en p\u00e9riode de floraison sans respecter les recommandations pour provoquer une catastrophe. Et il s'en produit trop souvent. Pour sortir de l'\u00ab orni\u00e8re du Gaucho \u00bb, l'antenne de Sophia Antipolis de l'Agence fran\u00e7aise de s\u00e9curit\u00e9 sanitaire des aliments et le laboratoire de l'Inra d'Avignon ont d\u00e9cid\u00e9 de cr\u00e9er un r\u00e9seau d'information sur les abeilles . Une heureuse initiative. Y. M. \u00a9 2001 Le Figaro. \",\n",
" 'bdd': 'europresse',\n",
" 'date': datetime.datetime(2001, 11, 9, 0, 0)}"
]
}
],
"prompt_number": 32
"prompt_number": 4
},
{
"cell_type": "code",
......@@ -322,26 +255,18 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 50
"prompt_number": 81
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"result = query_to_dicts('''select count(*),source \n",
" from documents_document \n",
" from documents_document\n",
" where project_id = %d\n",
" group by source\n",
" order by 1 DESC;''')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 57
},
{
"cell_type": "code",
"collapsed": false,
"input": [
" order by 1 DESC limit 9;''' % 1)\n",
"\n",
"for i in result:\n",
" print(i)"
],
......@@ -354,45 +279,33 @@
"text": [
"{'count': 34, 'source': 'Sud Ouest'}\n",
"{'count': 26, 'source': 'Le Progr\u00e8s - Lyon'}\n",
"{'count': 9, 'source': 'AFP Infos Fran\u00e7aises'}\n",
"{'count': 9, 'source': 'Le Figaro'}\n",
"{'count': 9, 'source': 'AFP Infos Fran\u00e7aises'}\n",
"{'count': 8, 'source': 'Les Echos'}\n",
"{'count': 8, 'source': 'Le Monde'}\n",
"{'count': 6, 'source': 'Le Parisien'}\n",
"{'count': 5, 'source': 'Le T\u00e9l\u00e9gramme (Bretagne)'}\n",
"{'count': 4, 'source': 'QUOTIDIEN PREMIERE EDITION'}\n",
"{'count': 4, 'source': 'Le Devoir'}\n",
"{'count': 4, 'source': 'La Presse'}\n",
"{'count': 3, 'source': 'Le Point'}\n",
"{'count': 3, 'source': 'Le Soleil'}\n",
"{'count': 3, 'source': 'La Tribune (France)'}\n",
"{'count': 3, 'source': 'La Tribune (Sherbrooke'}\n",
"{'count': 3, 'source': 'Le Nouvelliste (Trois-Rivi\u00e8res)'}\n",
"{'count': 3, 'source': 'News Press'}\n",
"{'count': 3, 'source': 'La Croix'}\n",
"{'count': 2, 'source': \"l'Humanit\u00e9\"}\n",
"{'count': 2, 'source': 'AFP Infos Economiques'}\n",
"{'count': 2, 'source': 'AFP Infos Mondiales'}\n",
"{'count': 2, 'source': 'Le Temps'}\n",
"{'count': 1, 'source': \"\u00c9crivains qu\u00e9b\u00e9cois - dossiers (L'\u00cele) - Le Devoir\"}\n",
"{'count': 1, 'source': \"La Voix de l'Est\"}\n",
"{'count': 1, 'source': \"L'Express\"}\n",
"{'count': 1, 'source': \"L'Acadie Nouvelle\"}\n",
"{'count': 1, 'source': 'La Presse Canadienne'}\n",
"{'count': 1, 'source': \"L'Actualit\u00e9\"}\n",
"{'count': 1, 'source': 'La Nouvelle R\u00e9publique du Centre-Ouest'}\n",
"{'count': 1, 'source': 'Progr\u00e8s-dimanche'}\n"
"{'count': 4, 'source': 'La Presse'}\n"
]
}
],
"prompt_number": 58
"prompt_number": 82
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 78
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"result = query_to_dicts('''select to_char(date, 'YYYY-MM'), count(*) \n",
" from documents_document \n",
" from documents_document\n",
" group by to_char(date, 'YYYY-MM')\n",
" order by 1 DESC;''')\n",
"for i in result:\n",
......@@ -450,9 +363,9 @@
"cell_type": "code",
"collapsed": false,
"input": [
"result = query_to_dicts('''select to_char(date, 'YYYY-MM-DD'), count(*) \n",
"result = query_to_dicts('''select to_char(date, 'YYYY-MM'), count(*) \n",
" from documents_document \n",
" group by to_char(date, 'YYYY-MM-DD')\n",
" group by to_char(date, 'YYYY-MM')\n",
" order by 1 DESC;''')\n",
"for i in result:\n",
" print(i)"
......@@ -464,116 +377,31 @@
"output_type": "stream",
"stream": "stdout",
"text": [
"{'to_char': '2001-12-29', 'count': 2}\n",
"{'to_char': '2001-12-22', 'count': 1}\n",
"{'to_char': '2001-12-17', 'count': 1}\n",
"{'to_char': '2001-12-15', 'count': 1}\n",
"{'to_char': '2001-12-13', 'count': 1}\n",
"{'to_char': '2001-12-12', 'count': 1}\n",
"{'to_char': '2001-12-10', 'count': 1}\n",
"{'to_char': '2001-12-05', 'count': 1}\n",
"{'to_char': '2001-11-27', 'count': 1}\n",
"{'to_char': '2001-11-26', 'count': 1}\n",
"{'to_char': '2001-11-24', 'count': 1}\n",
"{'to_char': '2001-11-20', 'count': 1}\n",
"{'to_char': '2001-11-14', 'count': 1}\n",
"{'to_char': '2001-11-09', 'count': 1}\n",
"{'to_char': '2001-11-06', 'count': 1}\n",
"{'to_char': '2001-11-03', 'count': 1}\n",
"{'to_char': '2001-11-02', 'count': 2}\n",
"{'to_char': '2001-10-10', 'count': 1}\n",
"{'to_char': '2001-10-05', 'count': 1}\n",
"{'to_char': '2001-09-25', 'count': 2}\n",
"{'to_char': '2001-09-22', 'count': 2}\n",
"{'to_char': '2001-09-13', 'count': 1}\n",
"{'to_char': '2001-09-12', 'count': 1}\n",
"{'to_char': '2001-09-05', 'count': 1}\n",
"{'to_char': '2001-09-04', 'count': 1}\n",
"{'to_char': '2001-09-03', 'count': 1}\n",
"{'to_char': '2001-09-01', 'count': 1}\n",
"{'to_char': '2001-08-31', 'count': 1}\n",
"{'to_char': '2001-08-23', 'count': 1}\n",
"{'to_char': '2001-08-22', 'count': 1}\n",
"{'to_char': '2001-08-21', 'count': 1}\n",
"{'to_char': '2001-08-20', 'count': 2}\n",
"{'to_char': '2001-08-19', 'count': 1}\n",
"{'to_char': '2001-08-17', 'count': 1}\n",
"{'to_char': '2001-08-15', 'count': 4}\n",
"{'to_char': '2001-08-14', 'count': 4}\n",
"{'to_char': '2001-08-13', 'count': 3}\n",
"{'to_char': '2001-08-11', 'count': 2}\n",
"{'to_char': '2001-08-10', 'count': 3}\n",
"{'to_char': '2001-08-09', 'count': 2}\n",
"{'to_char': '2001-08-08', 'count': 1}\n",
"{'to_char': '2001-08-07', 'count': 1}\n",
"{'to_char': '2001-08-06', 'count': 4}\n",
"{'to_char': '2001-08-04', 'count': 2}\n",
"{'to_char': '2001-08-03', 'count': 1}\n",
"{'to_char': '2001-08-02', 'count': 1}\n",
"{'to_char': '2001-07-28', 'count': 1}\n",
"{'to_char': '2001-07-27', 'count': 5}\n",
"{'to_char': '2001-07-26', 'count': 4}\n",
"{'to_char': '2001-07-23', 'count': 1}\n",
"{'to_char': '2001-07-16', 'count': 1}\n",
"{'to_char': '2001-07-13', 'count': 1}\n",
"{'to_char': '2001-07-12', 'count': 1}\n",
"{'to_char': '2001-07-10', 'count': 1}\n",
"{'to_char': '2001-06-28', 'count': 2}\n",
"{'to_char': '2001-06-25', 'count': 1}\n",
"{'to_char': '2001-06-24', 'count': 1}\n",
"{'to_char': '2001-06-21', 'count': 2}\n",
"{'to_char': '2001-06-20', 'count': 1}\n",
"{'to_char': '2001-06-19', 'count': 2}\n",
"{'to_char': '2001-06-14', 'count': 1}\n",
"{'to_char': '2001-06-07', 'count': 1}\n",
"{'to_char': '2001-06-04', 'count': 1}\n",
"{'to_char': '2001-05-25', 'count': 3}\n",
"{'to_char': '2001-05-24', 'count': 1}\n",
"{'to_char': '2001-05-19', 'count': 1}\n",
"{'to_char': '2001-05-11', 'count': 2}\n",
"{'to_char': '2001-05-10', 'count': 1}\n",
"{'to_char': '2001-05-08', 'count': 1}\n",
"{'to_char': '2001-05-07', 'count': 1}\n",
"{'to_char': '2001-05-03', 'count': 2}\n",
"{'to_char': '2001-05-02', 'count': 1}\n",
"{'to_char': '2001-04-27', 'count': 1}\n",
"{'to_char': '2001-04-26', 'count': 2}\n",
"{'to_char': '2001-04-21', 'count': 1}\n",
"{'to_char': '2001-04-17', 'count': 4}\n",
"{'to_char': '2001-04-16', 'count': 1}\n",
"{'to_char': '2001-04-12', 'count': 1}\n",
"{'to_char': '2001-04-11', 'count': 1}\n",
"{'to_char': '2001-04-07', 'count': 2}\n",
"{'to_char': '2001-03-22', 'count': 1}\n",
"{'to_char': '2001-03-21', 'count': 2}\n",
"{'to_char': '2001-03-20', 'count': 2}\n",
"{'to_char': '2001-03-17', 'count': 1}\n",
"{'to_char': '2001-03-16', 'count': 1}\n",
"{'to_char': '2001-03-14', 'count': 1}\n",
"{'to_char': '2001-03-12', 'count': 1}\n",
"{'to_char': '2001-03-09', 'count': 1}\n",
"{'to_char': '2001-03-06', 'count': 2}\n",
"{'to_char': '2001-03-04', 'count': 1}\n",
"{'to_char': '2001-03-03', 'count': 2}\n",
"{'to_char': '2001-03-02', 'count': 1}\n",
"{'to_char': '2001-02-21', 'count': 1}\n",
"{'to_char': '2001-02-20', 'count': 1}\n",
"{'to_char': '2001-02-16', 'count': 1}\n",
"{'to_char': '2001-02-15', 'count': 1}\n",
"{'to_char': '2001-02-13', 'count': 4}\n",
"{'to_char': '2001-02-09', 'count': 1}\n",
"{'to_char': '2001-02-08', 'count': 1}\n",
"{'to_char': '2001-02-07', 'count': 1}\n",
"{'to_char': '2001-02-06', 'count': 1}\n",
"{'to_char': '2001-02-05', 'count': 1}\n",
"{'to_char': '2001-02-03', 'count': 1}\n",
"{'to_char': '2001-01-21', 'count': 1}\n",
"{'to_char': '2001-01-14', 'count': 1}\n",
"{'to_char': '2001-01-11', 'count': 2}\n"
"{'to_char': '2001-12', 'count': 9}\n",
"{'to_char': '2001-11', 'count': 10}\n",
"{'to_char': '2001-10', 'count': 2}\n",
"{'to_char': '2001-09', 'count': 10}\n",
"{'to_char': '2001-08', 'count': 36}\n",
"{'to_char': '2001-07', 'count': 15}\n",
"{'to_char': '2001-06', 'count': 12}\n",
"{'to_char': '2001-05', 'count': 13}\n",
"{'to_char': '2001-04', 'count': 13}\n",
"{'to_char': '2001-03', 'count': 16}\n",
"{'to_char': '2001-02', 'count': 14}\n",
"{'to_char': '2001-01', 'count': 4}\n"
]
}
],
"prompt_number": 63
"prompt_number": 83
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 91
},
{
"cell_type": "code",
......
{
"metadata": {
"name": "",
"signature": "sha256:490e1bc5ac44087c1b3f82ca74e40f42f49bd3910f79a088af19c708d73c63e0"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
\ No newline at end of file
{
"metadata": {
"name": "",
"signature": "sha256:a8678c86f8d94c1ba55469d0e0a796c7d25df5de29707f5114b4cb74858855a8"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"cd .."
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"/home/alexandre/projets/gargantext.py\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import gargantext_core as gargantext"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cd gargantext_web/"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"/home/alexandre/projets/gargantext.py/gargantext_web\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import documents"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from collections import defaultdict"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Imporation\n",
"## Europresse"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"c = gargantext.bdd.Europresse()\n",
"c.add(\"/home/alexandre/projets/abeilles/documents/Europresse/html/\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"for doc in c:\n",
" d = documents.models.Document()\n",
" d.project_id = \"1\"\n",
" d.corpus_id = \"1\"\n",
" d.analyst_id = \"1\"\n",
" try:\n",
" d.uniqu_id = doc[\"object_id\"]\n",
" d.date = doc[\"date\"]\n",
" d.title = doc[\"title\"]\n",
" d.authors = doc[\"authors\"]\n",
" d.text = doc[\"text\"]\n",
" d.source = doc[\"source\"]\n",
" d.save()\n",
" except:\n",
" pass"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 88
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## ISI (todo)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"projects = documents.models.Project.objects.all()\n",
"for p in projects:\n",
" corpora = documents.models.Corpus.objects.filter(project_id=p.id)\n",
" print(p.id, p.title)\n",
" for c in corpora:\n",
" print(\"|_\", c.id,\":\", c.title)\n",
" print(\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"3 Hola Ebola\n",
"\n",
"2 Fukushima again\n",
"|_ 7 : Test\n",
"\n",
"4 Thanks anthrax\n",
"\n",
"1 Bees swarm\n",
"|_ 4 : Health academic publications\n",
"|_ 2 : bees and (pesticides or chemicals or neocotinoids)\n",
"|_ 1 : Quand les abeilles meurent, les articles sont compt\u00e9s\n",
"\n",
"6 CIRDEM\n",
"|_ 8 : Zotero fichier du 9 sept.\n",
"\n",
"7 TEST\n",
"\n"
]
}
],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def extractNgrams(corpus_pk=1):\n",
" corpus = documents.models.Corpus.objects.get(pk=1)\n",
" data = gargantext.Corpus()\n",
" docs = data.query('''select * from documents_document\n",
" where corpus_id = %d\n",
" limit 90;''' % corpus_pk)\n",
" words = gargantext.Ngrams()\n",
" words.get(docs, key='text', unique_id=\"unique_id\")\n",
" return(words)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import nltk\n",
"from nltk.stem.snowball import EnglishStemmer\n",
"stemmer = EnglishStemmer()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data = gargantext.Corpus()\n",
"docs = data.query('''select * from documents_document\n",
" where corpus_id = %d\n",
" limit 9;''' % 1)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def ngram(terms):\n",
" stems = stemmer.stem(terms)\n",
" n = len(stems.split(\" \"))\n",
" ngram = documents.models.Ngram.objects.get_or_create(terms = terms,\\\n",
" stem = stems,\\\n",
" n= n)\n",
" return(ngram[0])"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"doc = documents.models.Document.objects.get(pk = 9103)\n",
"doc.title"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 12,
"text": [
"'France/R\u00e9gent TS: contr\u00f4le judiciaire annul\u00e9 pour BASF, confirm\u00e9 pour Bayer'"
]
}
],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"gram = ngram(\"de\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 41
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def addNgram2doc(gram, doc):\n",
" ngramDoc = documents.models.NgramDocument.objects.get_or_create(terms=gram,\\\n",
" document = doc,\\\n",
" defaults={'occurrences':0})[0]\n",
" ngramDoc.occurrences = F('occurrences') + 1\n",
" ngramDoc.save()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 40
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Insert ngrams"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"l = set()\n",
"d = defaultdict(lambda : defaultdict(lambda: defaultdict(lambda: defaultdict(int))))\n",
"\n",
"docs = documents.models.Document.objects.all().filter(project_id=1)[:10] \n",
"\n",
"for doc in docs:\n",
" sentances = nltk.sent_tokenize(doc.text)\n",
" for sentance in sentances:\n",
" words = nltk.wordpunct_tokenize(sentance)\n",
" #print(len(words))\n",
" for word in words:\n",
" stems = stemmer.stem(word)\n",
" new = (word, stems, len(stems.split(\" \")))\n",
" l.add(new)\n",
" \n",
" d[word][doc.id]['count'] = d[word][doc.id].get('count', 0) + 1\n",
" \n",
"\n",
"new_grams = [documents.models.Ngram(terms=x[0], stem=x[1], n=x[2]) for x in l]\n",
"new_gramDoc = [ documents.models.NgramDocumentTemporary(terms=k, document=pk, occurrences=d[k][pk]['count']) \\\n",
" for k in d.keys() \\\n",
" for pk in d[k].keys()\\\n",
" ]\n",
"\n",
"documents.models.NgramTemporary.objects.bulk_create(new_grams)\n",
"documents.models.NgramDocumentTemporary.objects.bulk_create(new_gramDoc)\n",
"\n",
"from django.db import connection\n",
"cursor = connection.cursor()\n",
"# LOCK TABLE documents_ngramtemporary IN EXCLUSIVE MODE;\n",
"query_string = \"\"\"\n",
" INSERT INTO documents_ngram \n",
" SELECT * FROM documents_ngramtemporary WHERE NOT EXISTS \n",
" ( SELECT 1 FROM documents_ngram WHERE \n",
" documents_ngram.terms = documents_ngramtemporary.terms);\n",
" \n",
" delete from documents_ngramtemporary;\n",
" \n",
" INSERT INTO documents_ngramdocument\n",
" SELECT * FROM documents_ngramdocumenttemporary WHERE NOT EXISTS \n",
" ( SELECT 1 FROM documents_ngram WHERE \n",
" documents_ngram.terms = documents_ngramtemporary.terms);\n",
" \n",
" delete from documents_ngramtemporary;\n",
" \"\"\"\n",
"cursor.execute(query_string)\n",
"\n",
"try:\n",
" while True:\n",
" row = cursor.fetchone()\n",
" if row is None:\n",
" break\n",
" print(row)\n",
"except:\n",
" pass"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 21
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Insert NgramsDoc"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 20
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Copy Postgres"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 75
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 76
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"curs.execute(\"select * from documents_project;\")\n",
"curs.fetchone()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 77,
"text": [
"(3, datetime.date(2014, 9, 8), 1, 'Hola Ebola', 'Dance with the risks', {})"
]
}
],
"prompt_number": 77
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# anything can be used as a file if it has .read() and .readline() methods\n",
"import io\n",
"data = io.StringIO()\n",
"data.write('\\n'.join(['Test\\tretest\\t2',\n",
" 'Madonna\\tMado\\t45',\n",
" 'Federico\\tDi Gregorio\\t3']))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 81,
"text": [
"52"
]
}
],
"prompt_number": 81
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data.seek(0)\n",
"curs.copy_from(data, 'documents_ngramtemporary', columns=('terms', 'stem', 'n'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "InternalError",
"evalue": "ERREUR: la transaction est annul\u00e9e, les commandes sont ignor\u00e9es jusqu'\u00e0 la fin du bloc\nde la transaction\n",
"output_type": "pyerr",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mInternalError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-82-a9cf2ba7718f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mseek\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mcurs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcopy_from\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'documents_ngramtemporary'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'terms'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'stem'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'n'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mInternalError\u001b[0m: ERREUR: la transaction est annul\u00e9e, les commandes sont ignor\u00e9es jusqu'\u00e0 la fin du bloc\nde la transaction\n"
]
}
],
"prompt_number": 82
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 57
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 57
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 57
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x = extractNgrams()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"local variable 'x' referenced before assignment\n",
"local variable 'x' referenced before assignment"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"local variable 'x' referenced before assignment"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"local variable 'x' referenced before assignment"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"local variable 'x' referenced before assignment"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"local variable 'x' referenced before assignment"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"local variable 'x' referenced before assignment"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"local variable 'x' referenced before assignment"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "pyerr",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-9-d62560425026>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mextractNgrams\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m<ipython-input-8-520b3bdbed28>\u001b[0m in \u001b[0;36mextractNgrams\u001b[1;34m(corpus_pk)\u001b[0m\n\u001b[0;32m 6\u001b[0m limit 90;''' % corpus_pk)\n\u001b[0;32m 7\u001b[0m \u001b[0mwords\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgargantext\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mNgrams\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0mwords\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdocs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'text'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0munique_id\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"unique_id\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;32mreturn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mwords\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m/home/alexandre/projets/gargantext.py/gargantext_core/analysis/ngrams.py\u001b[0m in \u001b[0;36mget\u001b[1;34m(self, corpus, lang, key, unique_id)\u001b[0m\n\u001b[0;32m 96\u001b[0m \u001b[0mdate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdoc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'date'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'XX'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 97\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 98\u001b[1;33m \u001b[0mngrams\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfouille\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 99\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 100\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m/home/alexandre/projets/gargantext.py/gargantext_core/analysis/ngrams.py\u001b[0m in \u001b[0;36mfouille\u001b[1;34m(text, grammar_rule)\u001b[0m\n\u001b[0;32m 69\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0msentance\u001b[0m \u001b[1;32min\u001b[0m \u001b[0msentances\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 70\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 71\u001b[1;33m \u001b[0mt\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpos_tag\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msentance\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 72\u001b[0m \u001b[0mg\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgrammar\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mparse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mt\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 73\u001b[0m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mg\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msubtrees\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m/home/alexandre/projets/gargantext.py/gargantext_core/analysis/languages.py\u001b[0m in \u001b[0;36mfrench_pos_tag\u001b[1;34m(sentance)\u001b[0m\n\u001b[0;32m 67\u001b[0m \u001b[0mTAGINENC\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'utf-8'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0;31m\\\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 68\u001b[0m TAGOUTENC='utf-8')\n\u001b[1;32m---> 69\u001b[1;33m \u001b[0mtags\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtagger\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTagText\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msentance\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 70\u001b[0m \u001b[0mt\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtag\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtags\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 71\u001b[0m \u001b[1;32mreturn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mt\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m/home/alexandre/projets/gargantext.py/env/lib/python3.4/site-packages/treetaggerwrapper.py\u001b[0m in \u001b[0;36mTagText\u001b[1;34m(self, text, numlines, tagonly, prepronly, tagblanks, notagurl, notagemail, notagip, notagdns, encoding, errors)\u001b[0m\n\u001b[0;32m 1085\u001b[0m \u001b[0mintext\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1086\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m \u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1087\u001b[1;33m \u001b[0mline\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtagoutput\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadline\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1088\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mDEBUG\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mlogger\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdebug\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Read from TreeTagger: %r\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mline\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1089\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mline\u001b[0m \u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"d = documents.models.Document()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"for i in x.stems.keys():\n",
" print(i)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"('m\u00e9decin', 'classiqu')\n",
"('canc',)\n",
"('sourc', 'proch')\n",
"('carriol', '\u00e0', 'bagard')\n",
"('plant', 'cultiv')\n",
"('apr\u00e8s-mid', 'r\u00e9cr\u00e9at')\n",
"('ouest-fr', 'sarth', 'sud')\n",
"('jeun', '\u00e9lev')\n",
"('naus',)\n",
"('adult',)\n",
"('apres',)\n",
"('maison',)\n",
"('l',)\n",
"('jeud', 'soir')\n",
"('unaf',)\n",
"('don',)\n",
"('assurance-malad',)\n",
"('sol',)\n",
"('film', 'nos', 'enfant')\n",
"('concurrent', 'bai', 'cropscienc', 'franc')\n",
"('annul', 'd\u00e9pos')\n",
"('tel',)\n",
"('afriqu',)\n",
"('\u00eatre', '\u00e0', 'pied')\n",
"('group', 'lyon')\n",
"('quincy',)\n",
"('frelon', 'europ\u00e9en')\n",
"('mati', 'premi')\n",
"('d\u00e9sign', 'coupabl')\n",
"('\u00e9poqu',)\n",
"('affair',)\n",
"('bardeau',)\n",
"('jean-luc', 'souli')\n",
"('contr\u00f4l', 'judiciair')\n",
"('commercialis',)\n",
"('lieu',)\n",
"('semenc', 'trait')\n",
"('pr\u00e9par',)\n",
"('bai',)\n",
"('autr', 'problem')\n",
"('allerg',)\n",
"('suspens',)\n",
"('a-t-il', 'ajout')\n",
"('cadr',)\n",
"('absenc',)\n",
"('unit', 'finist\u00e9rien')\n",
"('infos', 'econom', 'r\u00e9gent', 't')\n",
"('commun',)\n",
"('semenc',)\n",
"('march', 'mondial')\n",
"('ventr',)\n",
"('not',)\n",
"('jean-mar',)\n",
"('jeud',)\n",
"('pet', 'boul')\n",
"('arbre',)\n",
"('examen',)\n",
"('asi',)\n",
"('jour',)\n",
"('agricultur', 'biolog')\n",
"('soir',)\n",
"('m\u00e9decin', 'hom\u00e9opath')\n",
"('client',)\n",
"('meus', 'vi', 'quotidien')\n",
"('croissanc',)\n",
"('toit',)\n",
"('mal-\u00eatr', 'g\u00e9n\u00e9ral')\n",
"('excellent', 'miel')\n",
"('\u00e9tudi', 'domicili')\n",
"('nouveaut',)\n",
"('chiffr',)\n",
"('d\u00e9monstr',)\n",
"('sit', 'brestois')\n",
"('bas',)\n",
"('volet',)\n",
"('v\u00e9g\u00e9tal',)\n",
"('histoir',)\n",
"('haute-garon',)\n",
"('jug', 'rama\u00ebl')\n",
"('mariag',)\n",
"('pr\u00e9dateur',)\n",
"('homm',)\n",
"('rachat',)\n",
"('id\u00e9',)\n",
"('\u00e9vident',)\n",
"('produit',)\n",
"('infarctus',)\n",
"('sid',)\n",
"('fruit',)\n",
"('deuxiem',)\n",
"('dgal', 'paris')\n",
"('r\u00e9sum',)\n",
"('visiteur',)\n",
"('public', 'passion')\n",
"('vend\u00f4mois',)\n",
"('\u00e9l\u00e9ment', 'naturel')\n",
"('surmortal',)\n",
"('appris', 'aupres')\n",
"('dat',)\n",
"('r\u00e9guli',)\n",
"('nid',)\n",
"('venin',)\n",
"('recel',)\n",
"('but',)\n",
"('recherch', 'perp\u00e9tuel')\n",
"('chauffag',)\n",
"('vi',)\n",
"('environ',)\n",
"('f\u00e9mur',)\n",
"('long',)\n",
"('f\u00e9vri',)\n",
"('cons\u00e9quent', 'p\u00e9nal')\n",
"('infos', 'econom', 'franc')\n",
"('hygien', 'tres', 'draconien')\n",
"('nichoir', 'r\u00e9alis')\n",
"('patholog',)\n",
"('expos',)\n",
"('\u00e9gal',)\n",
"('illustr',)\n",
"('pert',)\n",
"('magistrat', 'toulousain')\n",
"('macer',)\n",
"('ceven',)\n",
"('rayon',)\n",
"('proven',)\n",
"('l\u00e9gum',)\n",
"('ateli',)\n",
"('bagard',)\n",
"('d\u00e9but', 'mar')\n",
"('group',)\n",
"('conf\u00e9der', 'paysan')\n",
"('moment',)\n",
"('reper',)\n",
"('surexploit', 'industriel')\n",
"('m\u00eam',)\n",
"('plaint',)\n",
"('utilis', 'massif')\n",
"('fractur',)\n",
"('besseg',)\n",
"('\u00e9quinox',)\n",
"('h\u00f4tel', '\u00e0', 'insect')\n",
"('doublon',)\n",
"('dimanch',)\n",
"('produit', 'hom\u00e9opath')\n",
"('\u00e9colog',)\n",
"('aven',)\n",
"(\"c\u00f4tes-d'armor\",)\n",
"('f\u00e9liqu',)\n",
"('vu', '\u00e9conom')\n",
"('canton',)\n",
"('eau',)\n",
"('paris',)\n",
"('charg',)\n",
"('ouest-fr',)\n",
"('coll\u00e8gu',)\n",
"('demand',)\n",
"('anxiet',)\n",
"('saint-gauden', 'jean', 'guary')\n",
"('tres', 'satisfais')\n",
"('imm\u00e9diat',)\n",
"('condit',)\n",
"('bouff',)\n",
"('part', 'civil')\n",
"('mort',)\n",
"('bai', 'toulous')\n",
"('journ', 'port')\n",
"('magistrat',)\n",
"('il',)\n",
"('lydi', 'gravil')\n",
"('croissanc', 'correct')\n",
"('bon', 'rep')\n",
"('comprim',)\n",
"('beau', 'r\u00e9sultat')\n",
"('\u00e9pileps',)\n",
"('part',)\n",
"('inflig',)\n",
"('saint-gauden',)\n",
"('est', 'r\u00e9publicain')\n",
"('centr',)\n",
"('march',)\n",
"('d\u00e9savantag',)\n",
"('point',)\n",
"('europ',)\n",
"('appel',)\n",
"('d\u00e9bat',)\n",
"('gerb',)\n",
"('tub',)\n",
"('product',)\n",
"('d\u00e9tracteur',)\n",
"('ramassag',)\n",
"('aliment', 'viv')\n",
"('vendred',)\n",
"('an',)\n",
"('local',)\n",
"('manifest', 'ax\u00e9')\n",
"('ann\u00e9',)\n",
"('associ',)\n",
"('vin',)\n",
"('r\u00e9colt',)\n",
"('fan',)\n",
"('\u00eatre', 'pr\u00e9sent')\n",
"('union', 'national')\n",
"('fusion',)\n",
"('promen',)\n",
"('tres', 'simpl')\n",
"('\u00e9co-pieg',)\n",
"('fabriqu',)\n",
"('mid', 'libr')\n",
"('seb',)\n",
"('\u00a9',)\n",
"('grand', 'instanc')\n",
"('femm', 'favor')\n",
"('destruct',)\n",
"('particip',)\n",
"('centr', 'cultur')\n",
"('\u00e9nerg', 'nucl\u00e9air')\n",
"('arriv',)\n",
"('sifflet', 'bref')\n",
"('indemnis',)\n",
"('tri',)\n",
"('minister',)\n",
"('victim',)\n",
"('r\u00e9gent',)\n",
"('\u00e9chos', 'de', 'la', 'cez', 'semain', 'bleu')\n",
"('lot',)\n",
"('aub',)\n",
"('tribunal',)\n",
"('direct', 'g\u00e9n\u00e9ral')\n",
"('mck',)\n",
"('emploi', 'anthonin', 'debran')\n",
"('jug', 'guary')\n",
"('saccharos',)\n",
"('teintur', 'mer')\n",
"('m\u00e9dic',)\n",
"('autoris',)\n",
"('insect', 'diver')\n",
"('sos', 'abeil')\n",
"('enqu\u00eat',)\n",
"('solut', 'fiabl')\n",
"('indique-t-il',)\n",
"('amour',)\n",
"('b\u00e9b\u00eat',)\n",
"('\ufffduvr',)\n",
"('mesur',)\n",
"('robert',)\n",
"('semain',)\n",
"('salari',)\n",
"('aliment',)\n",
"('objet',)\n",
"('boiron',)\n",
"('b\u00eat',)\n",
"('situat',)\n",
"('est', 'r\u00e9publicain', 'ver')\n",
"('sein',)\n",
"('kergaradec',)\n",
"('\u00e0', 'savigny-sur-bray')\n",
"('ex-propri\u00e9tair',)\n",
"('ph\u00e9nomen', 'nouveau')\n",
"('confirm',)\n",
"('reproduct',)\n",
"('ouest-fr', 'finister')\n",
"('cha\u00een', 'compl\u00e9mentair')\n",
"('bernard', 'fau')\n",
"('\u00e9cosystem',)\n",
"('sac',)\n",
"('arr\u00eat',)\n",
"('oiseau',)\n",
"('million',)\n",
"('ajout', 'inconsider')\n",
"('apiculteur',)\n",
"('dgal',)\n",
"('lydi', 'villefeu')\n",
"('couleur',)\n",
"('espec', 'animal')\n",
"('societ', 'basf', 'agro')\n",
"('titr',)\n",
"('quart',)\n",
"('nombreux', 'expliqu')\n",
"('samed',)\n",
"('ancien', 'propri\u00e9tair')\n",
"('organis',)\n",
"('ale', 'le', '\u00e9chos', 'de', 'la', 'cez', 'semain', 'bleu')\n",
"('tgi',)\n",
"('\u00e9tabl',)\n",
"('supprim',)\n",
"('condit', 'tres', 'sp\u00e9cif')\n",
"('honneur',)\n",
"('semain', 'bleu')\n",
"('apr\u00e8s-mid',)\n",
"('principal', 'mission')\n",
"('milieu', 'naturel')\n",
"('conseil', 'g\u00e9n\u00e9ral')\n",
"('human',)\n",
"('insect',)\n",
"('\u00e9ventuel', 'nociv')\n",
"('pain',)\n",
"('r\u00e9pet',)\n",
"('octobr',)\n",
"('g\u00e9n\u00e9ral',)\n",
"('\u00e9quilibr', 'parf')\n",
"('lead', 'mondial')\n",
"('\u00e9coul',)\n",
"('bien',)\n",
"('bibliothequ', 'municipal')\n",
"('m\u00e9dic', 'traditionnel')\n",
"('stock',)\n",
"('sourc', 'judiciair')\n",
"('espec', 'v\u00e9g\u00e9tal')\n",
"('vapeur',)\n",
"('contenu',)\n",
"('pharmacien',)\n",
"('trac',)\n",
"('d\u00e9pen',)\n",
"('affair', 'jurid')\n",
"('sp\u00e9cial',)\n",
"('mas', 'serret')\n",
"('format',)\n",
"('vol',)\n",
"('propri\u00e9tair',)\n",
"('sommeil',)\n",
"('docu', 'suit')\n",
"('insecticid', 'r\u00e9gent')\n",
"('caution',)\n",
"('contr\u00f4l',)\n",
"('origin', 'v\u00e9g\u00e9tal')\n",
"('extinct',)\n",
"('bai', 'cropscienc', 'franc')\n",
"('habitud',)\n",
"('problem', 'environnemental')\n",
"('mercred',)\n",
"('machin',)\n",
"('zon',)\n",
"('travail',)\n",
"('f\u00e9vri', 'derni')\n",
"('agricultur',)\n",
"('basf', 'agro')\n",
"('chemin',)\n",
"('frelon', 'asiat')\n",
"('mond', 'enti')\n",
"('vill',)\n",
"('natur',)\n",
"('mid', 'libr', 'lozer')\n",
"('frelon',)\n",
"('parcour',)\n",
"('monstr',)\n",
"('camion', 'frigorif')\n",
"('\u00e0', 'vend\u00f4m')\n",
"('chambr',)\n",
"('cas',)\n",
"('nouveau', 'sp\u00e9cial')\n",
"('mair',)\n",
"('jardin', 'familial')\n",
"('laboratoir',)\n",
"('charpenti',)\n",
"('droit',)\n",
"('exempl',)\n",
"('toulous',)\n",
"('raison',)\n",
"('gu\u00e9rand',)\n",
"('basf',)\n",
"('difficult', '\u00e0')\n",
"('docu', 'communiqu')\n",
"('produit', 'chimiqu')\n",
"('horticulteur',)\n",
"('degr',)\n",
"('milit', 'agriculteur')\n",
"('infirmi',)\n",
"('bateau',)\n",
"('project',)\n",
"('juin',)\n",
"('centr', 'culturel')\n",
"('vice-pr\u00e9sident',)\n",
"('taigni',)\n",
"('conf\u00e9rent',)\n",
"('florenc', 'henry')\n",
"('chenill', 'processionnair')\n",
"('montm\u00e9dien',)\n",
"('renseign',)\n",
"('centre-ouest',)\n",
"('gu\u00eap',)\n",
"('sit',)\n",
"('disparit',)\n",
"('essaim', 'd')\n",
"('fipronil',)\n",
"('exploit',)\n",
"('chass', 'cafard')\n",
"('bernard', 'portales')\n",
"('\u00e9cout',)\n",
"('ccas',)\n",
"('rigolad',)\n",
"('meilleur', 'v\ufffdu')\n",
"('abeil',)\n",
"('chimioth\u00e9rap',)\n",
"('chaleur',)\n",
"('moyen',)\n",
"('diff\u00e9rent', 'pharmacien')\n",
"('journ',)\n",
"('dout',)\n",
"('exploit', 'horticol', '\u00e9colog')\n",
"('air',)\n",
"('public',)\n",
"('autr', 'arr\u00eat')\n",
"('plac',)\n",
"('siecl',)\n",
"('fau',)\n",
"('directeur|directric',)\n",
"('tres',)\n",
"('nouveau', 'ordon', 'conform')\n",
"('diabet',)\n",
"('jug',)\n",
"('cloqu',)\n",
"('cycl',)\n",
"('euro',)\n",
"('anim',)\n",
"('colleret',)\n",
"('action',)\n",
"('br\u00fblur', 'local')\n",
"('porspod',)\n",
"('produit', 'issu')\n",
"('pesticid',)\n",
"('popul', 'd')\n",
"('imag',)\n",
"('trentain',)\n",
"('aux', 'beau')\n",
"('proc\u00e9dur',)\n",
"('terr',)\n",
"('produit', 'diff\u00e9rent')\n",
"('yves-mar', 'robin')\n",
"('moulin', 'robert')\n",
"('instruct',)\n",
"('alcool',)\n",
"('alpe',)\n",
"('dangeros',)\n",
"('societ',)\n",
"('porte-parol', 'jos', 'bov')\n",
"('coll\u00e8gu', 'jean', 'guary')\n",
"('occup',)\n",
"('potag',)\n",
"('ministr',)\n",
"('ami',)\n",
"('sant',)\n",
"('gest', 'simpl')\n",
"('fond',)\n",
"('mis',)\n",
"('insect', 'tres', 'util')\n",
"('ndy', '\u00a9')\n",
"('attent', 'port')\n",
"('avocat',)\n",
"('forc',)\n",
"('f\u00eat',)\n",
"('femm',)\n",
"('mond',)\n",
"('them',)\n",
"('beau', 'affluenc')\n",
"('lutf', 'kocyig')\n",
"('insecticid', 'r\u00e9gent', 't')\n",
"('r\u00e9seau',)\n",
"('patienc',)\n",
"('lactos',)\n",
"('infos', 'fran\u00e7ais', 'r\u00e9gent', 't')\n",
"('particuli',)\n",
"('coup',)\n",
"('florenc',)\n",
"('extr\u00eam', 'orient')\n",
"('d\u00e9cis',)\n",
"('habitat',)\n",
"('gard',)\n",
"('algu',)\n",
"('anciennet', 'derri')\n",
"('transmiss',)\n",
"('facil', '\u00e0')\n",
"('contact',)\n",
"('chim',)\n",
"('lead', 'incontest')\n",
"('princip', 'actif')\n",
"('hom\u00e9opath',)\n",
"('grain',)\n",
"('norm',)\n",
"('gamm',)\n",
"('engrais', 'chimiqu')\n",
"('c\ufffdur',)\n",
"('chl', '\u00a9')\n",
"('concurrent', 'direct')\n",
"('farin',)\n",
"('mar', '@ord@')\n",
"('caus',)\n",
"('nouveau', 'moyen')\n",
"('publiqu',)\n",
"('cultur', 'intens')\n",
"('moulin',)\n",
"('d\u00e9part',)\n",
"('cop',)\n",
"('fleur',)\n",
"('dolisos',)\n",
"('c\u00f4t',)\n",
"('soin',)\n",
"('servic',)\n",
"('bois',)\n",
"('sujet',)\n",
"('maxim', 'ortin')\n",
"('cultur', 'biolog')\n",
"('\u00eatre',)\n",
"('derni',)\n",
"('lois',)\n",
"('orchestr', 'alain', 'mayo')\n",
"('nich',)\n",
"('franc',)\n",
"('bonheur',)\n",
"('centre-ouest', 'loir', 'et', 'cher', 'vendom', 'et')\n",
"('humor', 'andy', 'klein')\n",
"('morbihan',)\n",
"('jus',)\n",
"('pa',)\n",
"('caracter', 'particuli')\n",
"('sel',)\n",
"('jeun',)\n",
"('plui',)\n",
"('cultur', 'biolog', 'accessibl')\n",
"('autr', 'ordon')\n",
"('docu',)\n",
"('retrait',)\n",
"('entretien',)\n",
"('jug', 'patrick', 'rama\u00ebl')\n",
"('dossi',)\n",
"('d\u00e9fens',)\n",
"('cultur',)\n",
"('rest',)\n",
"('curieux',)\n",
"('anthonin',)\n",
"('terrain',)\n",
"('nouvel', 'r\u00e9publ')\n",
"('kutf',)\n",
"('\u00e0',)\n",
"('m\u00e9decin',)\n",
"('fin',)\n",
"('gill',)\n",
"('tout', 'gentil')\n",
"('pollinis',)\n",
"('vers',)\n",
"('cour',)\n",
"('annul',)\n",
"('bl\u00e9',)\n",
"('interdict',)\n",
"('\u00e9gal', 'pr\u00e9dateur')\n",
"('long', 'travail')\n",
"('person',)\n",
"('brest',)\n",
"('dizain',)\n",
"('miel',)\n",
"('enfant',)\n",
"('animal',)\n",
"('copeau',)\n",
"('tiroir',)\n",
"('r\u00e9gent', 't')\n",
"('foi|fois',)\n",
"('organ',)\n",
"('plant',)\n",
"('bon', 'temp')\n",
"('malad',)\n",
"('vent',)\n",
"('apicultur', 'fran\u00e7ais')\n",
"('antonin',)\n",
"('futur', '\u00e9poux')\n",
"('insect', 'nuisibl')\n",
"('d\u00e9p\u00f4t',)\n",
"('stress',)\n",
"('fort', 'progress')\n",
"('madagascar',)\n",
"('sall',)\n"
]
}
],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"corpus.language.language"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 72,
"text": [
"'French'"
]
}
],
"prompt_number": 72
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 69
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"for doc in corpus_dict:\n",
" print(doc.get('title', ''))"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 20
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 73
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"gram = documents.models.Ngram()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 58
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x = documents.models.NgramDocument()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 61
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"jj_nn = r\"\"\"\n",
" NP: \n",
" {<JJ.*>*<NN.*|>+<JJ.*>*}\n",
" \"\"\""
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 64
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import nltk"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 65
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"grammar = nltk.sent_tokenize(jj_nn)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 66
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def "
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 66
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"documents.models.Document.objects.raw('select count(*),source from documents_document group by source;'):"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "InvalidQuery",
"evalue": "Raw query must include the primary key",
"output_type": "pyerr",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mInvalidQuery\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-45-5495b08ea061>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0mp\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mdocuments\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmodels\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDocument\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobjects\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mraw\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'select count(*),source from documents_document group by source;'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mp\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m/home/alexandre/projets/gargantext.py/env/lib/python3.4/site-packages/django/db/models/query.py\u001b[0m in \u001b[0;36m__iter__\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1413\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mskip\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1414\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_meta\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpk\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mattname\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mskip\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1415\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mInvalidQuery\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Raw query must include the primary key'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1416\u001b[0m \u001b[0mmodel_cls\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdeferred_class_factory\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mskip\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1417\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mInvalidQuery\u001b[0m: Raw query must include the primary key"
]
}
],
"prompt_number": 45
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"{'count': 34, 'source': 'Sud Ouest'}\n",
"{'count': 26, 'source': 'Le Progr\u00e8s - Lyon'}\n",
"{'count': 9, 'source': 'Le Figaro'}\n",
"{'count': 9, 'source': 'AFP Infos Fran\u00e7aises'}\n",
"{'count': 8, 'source': 'Les Echos'}\n",
"{'count': 8, 'source': 'Le Monde'}\n",
"{'count': 6, 'source': 'Le Parisien'}\n",
"{'count': 5, 'source': 'Le T\u00e9l\u00e9gramme (Bretagne)'}\n",
"{'count': 4, 'source': 'La Presse'}\n"
]
}
],
"prompt_number": 82
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 78
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"result = query_to_dicts('''select to_char(date, 'YYYY-MM'), count(*) \n",
" from documents_document\n",
" group by to_char(date, 'YYYY-MM')\n",
" order by 1 DESC;''')\n",
"for i in result:\n",
" print(i)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"{'to_char': '2001-12', 'count': 9}\n",
"{'to_char': '2001-11', 'count': 10}\n",
"{'to_char': '2001-10', 'count': 2}\n",
"{'to_char': '2001-09', 'count': 10}\n",
"{'to_char': '2001-08', 'count': 36}\n",
"{'to_char': '2001-07', 'count': 15}\n",
"{'to_char': '2001-06', 'count': 12}\n",
"{'to_char': '2001-05', 'count': 13}\n",
"{'to_char': '2001-04', 'count': 13}\n",
"{'to_char': '2001-03', 'count': 16}\n",
"{'to_char': '2001-02', 'count': 14}\n",
"{'to_char': '2001-01', 'count': 4}\n"
]
}
],
"prompt_number": 61
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"result = query_to_dicts('''select to_char(date, 'YYYY'), count(*) \n",
" from documents_document \n",
" group by to_char(date, 'YYYY')\n",
" order by 1 DESC;''')\n",
"for i in result:\n",
" print(i)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"{'to_char': '2001', 'count': 154}\n"
]
}
],
"prompt_number": 62
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"result = query_to_dicts('''select to_char(date, 'YYYY-MM'), count(*) \n",
" from documents_document \n",
" group by to_char(date, 'YYYY-MM')\n",
" order by 1 DESC;''')\n",
"for i in result:\n",
" print(i)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"{'to_char': '2001-12', 'count': 9}\n",
"{'to_char': '2001-11', 'count': 10}\n",
"{'to_char': '2001-10', 'count': 2}\n",
"{'to_char': '2001-09', 'count': 10}\n",
"{'to_char': '2001-08', 'count': 36}\n",
"{'to_char': '2001-07', 'count': 15}\n",
"{'to_char': '2001-06', 'count': 12}\n",
"{'to_char': '2001-05', 'count': 13}\n",
"{'to_char': '2001-04', 'count': 13}\n",
"{'to_char': '2001-03', 'count': 16}\n",
"{'to_char': '2001-02', 'count': 14}\n",
"{'to_char': '2001-01', 'count': 4}\n"
]
}
],
"prompt_number": 83
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 91
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
\ No newline at end of file
{
"metadata": {
"name": "",
"signature": "sha256:bf2595e789140e8e70cb8461a7bd41413d759a51f3c940626bc8ef6856a320e3"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"cd .."
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"/home/alexandre/projets/gargantext.py\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import gargantext_core as gargantext"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cd gargantext_web/"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"/home/alexandre/projets/gargantext.py/gargantext_web\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import documents"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import nltk\n",
"from nltk.stem.snowball import EnglishStemmer\n",
"stemmer = EnglishStemmer()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from collections import defaultdict"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Imporation\n",
"## Europresse"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"c = gargantext.bdd.Europresse()\n",
"c.add(\"/home/alexandre/projets/abeilles/documents/Europresse/html/\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"for doc in c:\n",
" d = documents.models.Document()\n",
" d.project_id = \"1\"\n",
" d.corpus_id = \"1\"\n",
" d.analyst_id = \"1\"\n",
" try:\n",
" d.uniqu_id = doc[\"object_id\"]\n",
" d.date = doc[\"date\"]\n",
" d.title = doc[\"title\"]\n",
" d.authors = doc[\"authors\"]\n",
" d.text = doc[\"text\"]\n",
" d.source = doc[\"source\"]\n",
" d.save()\n",
" except:\n",
" pass"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 88
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## ISI (todo)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"projects = documents.models.Project.objects.all()\n",
"for p in projects:\n",
" corpora = documents.models.Corpus.objects.filter(project_id=p.id)\n",
" print(p.id, p.title)\n",
" for c in corpora:\n",
" print(\"|_\", c.id,\":\", c.title)\n",
" print(\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"3 Hola Ebola\n",
"\n",
"2 Fukushima again\n",
"|_ 7 : Test\n",
"\n",
"4 Thanks anthrax\n",
"\n",
"1 Bees swarm\n",
"|_ 9 : Bees tweets\n",
"|_ 4 : Health academic publications\n",
"|_ 2 : bees and (pesticides or chemicals or neocotinoids)\n",
"|_ 1 : Quand les abeilles meurent, les articles sont compt\u00e9s\n",
"\n",
"6 CIRDEM\n",
"|_ 8 : Zotero fichier du 9 sept.\n",
"\n"
]
}
],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def extractNgrams(corpus_pk=1):\n",
" corpus = documents.models.Corpus.objects.get(pk=1)\n",
" data = gargantext.Corpus()\n",
" docs = data.query('''select * from documents_document\n",
" where corpus_id = %d\n",
" limit 90;''' % corpus_pk)\n",
" words = gargantext.Ngrams()\n",
" words.get(docs, key='text', unique_id=\"unique_id\")\n",
" return(words)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 29
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data = gargantext.Corpus()\n",
"docs = data.query('''select * from documents_document\n",
" where corpus_id = %d\n",
" limit 9;''' % 1)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def ngram(terms):\n",
" stems = stemmer.stem(terms)\n",
" n = len(stems.split(\" \"))\n",
" ngram = documents.models.Ngram.objects.get_or_create(terms = terms,\\\n",
" stem = stems,\\\n",
" n= n)\n",
" return(ngram[0])"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"doc = documents.models.Document.objects.get(pk = 9103)\n",
"doc.title"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"text": [
"'France/R\u00e9gent TS: contr\u00f4le judiciaire annul\u00e9 pour BASF, confirm\u00e9 pour Bayer'"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"gram = ngram(\"de\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 41
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def addNgram2doc(gram, doc):\n",
" ngramDoc = documents.models.NgramDocument.objects.get_or_create(terms=gram,\\\n",
" document = doc,\\\n",
" defaults={'occurrences':0})[0]\n",
" ngramDoc.occurrences = F('occurrences') + 1\n",
" ngramDoc.save()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 40
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Insert ngrams"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"l = set()\n",
"d = defaultdict(lambda : defaultdict(lambda: defaultdict(lambda: defaultdict(int))))\n",
"\n",
"docs = documents.models.Document.objects.all().filter(project_id=1)[:1000] \n",
"\n",
"for doc in docs:\n",
" sentences = nltk.sent_tokenize(doc.text)\n",
" for sentence in sentences:\n",
" words = nltk.wordpunct_tokenize(sentence)\n",
" #print(len(words))\n",
" for word in words:\n",
" stems = stemmer.stem(word)\n",
" new = (word, stems, len(stems.split(\" \")))\n",
" l.add(new)\n",
" \n",
" d[word][doc.id]['count'] = d[word][doc.id].get('count', 0) + 1\n",
" \n",
"\n",
"new_grams = [documents.models.Ngram(terms=x[0], stem=x[1], n=x[2]) for x in l]\n",
"new_gramDoc = [ documents.models.NgramDocumentTemporary(terms=k, document=pk, occurrences=d[k][pk]['count']) \\\n",
" for k in d.keys() \\\n",
" for pk in d[k].keys()\\\n",
" ]"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"documents.models.NgramTemporary.objects.bulk_create(new_grams)\n",
"documents.models.NgramDocumentTemporary.objects.bulk_create(new_gramDoc)\n",
"\n",
"from django.db import connection\n",
"cursor = connection.cursor()\n",
"# LOCK TABLE documents_ngramtemporary IN EXCLUSIVE MODE;\n",
"query_string = \"\"\"\n",
" INSERT INTO documents_ngram \n",
" SELECT * FROM documents_ngramtemporary WHERE NOT EXISTS \n",
" ( SELECT 1 FROM documents_ngram WHERE \n",
" documents_ngram.terms = documents_ngramtemporary.terms);\n",
" \n",
" delete from documents_ngramtemporary;\n",
" \n",
" INSERT INTO \n",
" documents_ngramdocument (terms_id, document_id, occurrences)\n",
" SELECT \n",
" GT.id, DT.id, NDT.occurrences \n",
" FROM \n",
" documents_ngramdocumenttemporary as NDT \n",
" INNER JOIN documents_document AS DT ON DT.id = NDT.document \n",
" INNER JOIN documents_ngram AS GT ON GT.terms = NDT.terms ;\n",
" \n",
" delete from documents_ngramdocumenttemporary;\n",
" \"\"\"\n",
"cursor.execute(query_string)\n",
"\n",
"try:\n",
" while True:\n",
" row = cursor.fetchone()\n",
" if row is None:\n",
" break\n",
" print(row)\n",
"except:\n",
" pass"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Insert NgramsDoc"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"SELECT t1.terms_id, t2.terms_id, COUNT(*) AS c, t3.project_id\n",
"FROM documents_ngramdocument AS t1\n",
"\n",
"INNER JOIN documents_ngramdocument AS t2\n",
"ON t1.document_id = t2.document_id\n",
"\n",
"INNER JOIN documents_corpus\n",
"\n",
"GROUP BY t1.terms_id, t2.terms_id;\n",
"\n",
"# add corpus_id in column !"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 20
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Coocurrences"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 75
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 76
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"curs.execute(\"select * from documents_project;\")\n",
"curs.fetchone()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 77,
"text": [
"(3, datetime.date(2014, 9, 8), 1, 'Hola Ebola', 'Dance with the risks', {})"
]
}
],
"prompt_number": 77
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# anything can be used as a file if it has .read() and .readline() methods\n",
"import io\n",
"data = io.StringIO()\n",
"data.write('\\n'.join(['Test\\tretest\\t2',\n",
" 'Madonna\\tMado\\t45',\n",
" 'Federico\\tDi Gregorio\\t3']))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 81,
"text": [
"52"
]
}
],
"prompt_number": 81
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data.seek(0)\n",
"curs.copy_from(data, 'documents_ngramtemporary', columns=('terms', 'stem', 'n'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "InternalError",
"evalue": "ERREUR: la transaction est annul\u00e9e, les commandes sont ignor\u00e9es jusqu'\u00e0 la fin du bloc\nde la transaction\n",
"output_type": "pyerr",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mInternalError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-82-a9cf2ba7718f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mseek\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mcurs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcopy_from\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'documents_ngramtemporary'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'terms'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'stem'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'n'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mInternalError\u001b[0m: ERREUR: la transaction est annul\u00e9e, les commandes sont ignor\u00e9es jusqu'\u00e0 la fin du bloc\nde la transaction\n"
]
}
],
"prompt_number": 82
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 57
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 57
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 57
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 72,
"text": [
"'French'"
]
}
],
"prompt_number": 72
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 69
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 20
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 73
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 58
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 61
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 64
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 65
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 78
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 91
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
\ No newline at end of file
.easyPieChart {
position: relative;
text-align: center;
}
.easyPieChart canvas {
position: absolute;
top: 0;
left: 0;
}
/**!
* easyPieChart
* Lightweight plugin to render simple, animated and retina optimized pie charts
*
* @license
* @author Robert Fleischmann <rendro87@gmail.com> (http://robert-fleischmann.de)
* @version 2.1.5
**/
(function(root, factory) {
if(typeof exports === 'object') {
module.exports = factory(require('angular'));
}
else if(typeof define === 'function' && define.amd) {
define(['angular'], factory);
}
else {
factory(root.angular);
}
}(this, function(angular) {
(function (angular) {
'use strict';
return angular.module('easypiechart', [])
.directive('easypiechart', [function() {
return {
restrict: 'A',
require: '?ngModel',
scope: {
percent: '=',
options: '='
},
link: function (scope, element, attrs) {
scope.percent = scope.percent || 0;
/**
* default easy pie chart options
* @type {Object}
*/
var options = {
barColor: '#ef1e25',
trackColor: '#f9f9f9',
scaleColor: '#dfe0e0',
scaleLength: 5,
lineCap: 'round',
lineWidth: 3,
size: 110,
rotate: 0,
animate: {
duration: 1000,
enabled: true
}
};
scope.options = angular.extend(options, scope.options);
var pieChart = new EasyPieChart(element[0], options);
scope.$watch('percent', function(newVal, oldVal) {
pieChart.update(newVal);
});
}
};
}]);
})(angular);
/**
* Renderer to render the chart on a canvas object
* @param {DOMElement} el DOM element to host the canvas (root of the plugin)
* @param {object} options options object of the plugin
*/
var CanvasRenderer = function(el, options) {
var cachedBackground;
var canvas = document.createElement('canvas');
el.appendChild(canvas);
if (typeof(G_vmlCanvasManager) !== 'undefined') {
G_vmlCanvasManager.initElement(canvas);
}
var ctx = canvas.getContext('2d');
canvas.width = canvas.height = options.size;
// canvas on retina devices
var scaleBy = 1;
if (window.devicePixelRatio > 1) {
scaleBy = window.devicePixelRatio;
canvas.style.width = canvas.style.height = [options.size, 'px'].join('');
canvas.width = canvas.height = options.size * scaleBy;
ctx.scale(scaleBy, scaleBy);
}
// move 0,0 coordinates to the center
ctx.translate(options.size / 2, options.size / 2);
// rotate canvas -90deg
ctx.rotate((-1 / 2 + options.rotate / 180) * Math.PI);
var radius = (options.size - options.lineWidth) / 2;
if (options.scaleColor && options.scaleLength) {
radius -= options.scaleLength + 2; // 2 is the distance between scale and bar
}
// IE polyfill for Date
Date.now = Date.now || function() {
return +(new Date());
};
/**
* Draw a circle around the center of the canvas
* @param {strong} color Valid CSS color string
* @param {number} lineWidth Width of the line in px
* @param {number} percent Percentage to draw (float between -1 and 1)
*/
var drawCircle = function(color, lineWidth, percent) {
percent = Math.min(Math.max(-1, percent || 0), 1);
var isNegative = percent <= 0 ? true : false;
ctx.beginPath();
ctx.arc(0, 0, radius, 0, Math.PI * 2 * percent, isNegative);
ctx.strokeStyle = color;
ctx.lineWidth = lineWidth;
ctx.stroke();
};
/**
* Draw the scale of the chart
*/
var drawScale = function() {
var offset;
var length;
ctx.lineWidth = 1;
ctx.fillStyle = options.scaleColor;
ctx.save();
for (var i = 24; i > 0; --i) {
if (i % 6 === 0) {
length = options.scaleLength;
offset = 0;
} else {
length = options.scaleLength * 0.6;
offset = options.scaleLength - length;
}
ctx.fillRect(-options.size/2 + offset, 0, length, 1);
ctx.rotate(Math.PI / 12);
}
ctx.restore();
};
/**
* Request animation frame wrapper with polyfill
* @return {function} Request animation frame method or timeout fallback
*/
var reqAnimationFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
}());
/**
* Draw the background of the plugin including the scale and the track
*/
var drawBackground = function() {
if(options.scaleColor) drawScale();
if(options.trackColor) drawCircle(options.trackColor, options.lineWidth, 1);
};
/**
* Canvas accessor
*/
this.getCanvas = function() {
return canvas;
};
/**
* Canvas 2D context 'ctx' accessor
*/
this.getCtx = function() {
return ctx;
};
/**
* Clear the complete canvas
*/
this.clear = function() {
ctx.clearRect(options.size / -2, options.size / -2, options.size, options.size);
};
/**
* Draw the complete chart
* @param {number} percent Percent shown by the chart between -100 and 100
*/
this.draw = function(percent) {
// do we need to render a background
if (!!options.scaleColor || !!options.trackColor) {
// getImageData and putImageData are supported
if (ctx.getImageData && ctx.putImageData) {
if (!cachedBackground) {
drawBackground();
cachedBackground = ctx.getImageData(0, 0, options.size * scaleBy, options.size * scaleBy);
} else {
ctx.putImageData(cachedBackground, 0, 0);
}
} else {
this.clear();
drawBackground();
}
} else {
this.clear();
}
ctx.lineCap = options.lineCap;
// if barcolor is a function execute it and pass the percent as a value
var color;
if (typeof(options.barColor) === 'function') {
color = options.barColor(percent);
} else {
color = options.barColor;
}
// draw bar
drawCircle(color, options.lineWidth, percent / 100);
}.bind(this);
/**
* Animate from some percent to some other percentage
* @param {number} from Starting percentage
* @param {number} to Final percentage
*/
this.animate = function(from, to) {
var startTime = Date.now();
options.onStart(from, to);
var animation = function() {
var process = Math.min(Date.now() - startTime, options.animate.duration);
var currentValue = options.easing(this, process, from, to - from, options.animate.duration);
this.draw(currentValue);
options.onStep(from, to, currentValue);
if (process >= options.animate.duration) {
options.onStop(from, to);
} else {
reqAnimationFrame(animation);
}
}.bind(this);
reqAnimationFrame(animation);
}.bind(this);
};
var EasyPieChart = function(el, opts) {
var defaultOptions = {
barColor: '#ef1e25',
trackColor: '#f9f9f9',
scaleColor: '#dfe0e0',
scaleLength: 5,
lineCap: 'round',
lineWidth: 3,
size: 110,
rotate: 0,
animate: {
duration: 1000,
enabled: true
},
easing: function (x, t, b, c, d) { // more can be found here: http://gsgd.co.uk/sandbox/jquery/easing/
t = t / (d/2);
if (t < 1) {
return c / 2 * t * t + b;
}
return -c/2 * ((--t)*(t-2) - 1) + b;
},
onStart: function(from, to) {
return;
},
onStep: function(from, to, currentValue) {
return;
},
onStop: function(from, to) {
return;
}
};
// detect present renderer
if (typeof(CanvasRenderer) !== 'undefined') {
defaultOptions.renderer = CanvasRenderer;
} else if (typeof(SVGRenderer) !== 'undefined') {
defaultOptions.renderer = SVGRenderer;
} else {
throw new Error('Please load either the SVG- or the CanvasRenderer');
}
var options = {};
var currentValue = 0;
/**
* Initialize the plugin by creating the options object and initialize rendering
*/
var init = function() {
this.el = el;
this.options = options;
// merge user options into default options
for (var i in defaultOptions) {
if (defaultOptions.hasOwnProperty(i)) {
options[i] = opts && typeof(opts[i]) !== 'undefined' ? opts[i] : defaultOptions[i];
if (typeof(options[i]) === 'function') {
options[i] = options[i].bind(this);
}
}
}
// check for jQuery easing
if (typeof(options.easing) === 'string' && typeof(jQuery) !== 'undefined' && jQuery.isFunction(jQuery.easing[options.easing])) {
options.easing = jQuery.easing[options.easing];
} else {
options.easing = defaultOptions.easing;
}
// process earlier animate option to avoid bc breaks
if (typeof(options.animate) === 'number') {
options.animate = {
duration: options.animate,
enabled: true
};
}
if (typeof(options.animate) === 'boolean' && !options.animate) {
options.animate = {
duration: 1000,
enabled: options.animate
};
}
// create renderer
this.renderer = new options.renderer(el, options);
// initial draw
this.renderer.draw(currentValue);
// initial update
if (el.dataset && el.dataset.percent) {
this.update(parseFloat(el.dataset.percent));
} else if (el.getAttribute && el.getAttribute('data-percent')) {
this.update(parseFloat(el.getAttribute('data-percent')));
}
}.bind(this);
/**
* Update the value of the chart
* @param {number} newValue Number between 0 and 100
* @return {object} Instance of the plugin for method chaining
*/
this.update = function(newValue) {
newValue = parseFloat(newValue);
if (options.animate.enabled) {
this.renderer.animate(currentValue, newValue);
} else {
this.renderer.draw(newValue);
}
currentValue = newValue;
return this;
}.bind(this);
/**
* Disable animation
* @return {object} Instance of the plugin for method chaining
*/
this.disableAnimation = function() {
options.animate.enabled = false;
return this;
};
/**
* Enable animation
* @return {object} Instance of the plugin for method chaining
*/
this.enableAnimation = function() {
options.animate.enabled = true;
return this;
};
init();
};
}));
/**!
* easyPieChart
* Lightweight plugin to render simple, animated and retina optimized pie charts
*
* @license
* @author Robert Fleischmann <rendro87@gmail.com> (http://robert-fleischmann.de)
* @version 2.1.5
**/
!function(a,b){"object"==typeof exports?module.exports=b(require("angular")):"function"==typeof define&&define.amd?define(["angular"],b):b(a.angular)}(this,function(a){!function(a){"use strict";return a.module("easypiechart",[]).directive("easypiechart",[function(){return{restrict:"A",require:"?ngModel",scope:{percent:"=",options:"="},link:function(b,d){b.percent=b.percent||0;var e={barColor:"#ef1e25",trackColor:"#f9f9f9",scaleColor:"#dfe0e0",scaleLength:5,lineCap:"round",lineWidth:3,size:110,rotate:0,animate:{duration:1e3,enabled:!0}};b.options=a.extend(e,b.options);var f=new c(d[0],e);b.$watch("percent",function(a){f.update(a)})}}}])}(a);var b=function(a,b){var c,d=document.createElement("canvas");a.appendChild(d),"undefined"!=typeof G_vmlCanvasManager&&G_vmlCanvasManager.initElement(d);var e=d.getContext("2d");d.width=d.height=b.size;var f=1;window.devicePixelRatio>1&&(f=window.devicePixelRatio,d.style.width=d.style.height=[b.size,"px"].join(""),d.width=d.height=b.size*f,e.scale(f,f)),e.translate(b.size/2,b.size/2),e.rotate((-0.5+b.rotate/180)*Math.PI);var g=(b.size-b.lineWidth)/2;b.scaleColor&&b.scaleLength&&(g-=b.scaleLength+2),Date.now=Date.now||function(){return+new Date};var h=function(a,b,c){c=Math.min(Math.max(-1,c||0),1);var d=0>=c?!0:!1;e.beginPath(),e.arc(0,0,g,0,2*Math.PI*c,d),e.strokeStyle=a,e.lineWidth=b,e.stroke()},i=function(){var a,c;e.lineWidth=1,e.fillStyle=b.scaleColor,e.save();for(var d=24;d>0;--d)d%6===0?(c=b.scaleLength,a=0):(c=.6*b.scaleLength,a=b.scaleLength-c),e.fillRect(-b.size/2+a,0,c,1),e.rotate(Math.PI/12);e.restore()},j=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}(),k=function(){b.scaleColor&&i(),b.trackColor&&h(b.trackColor,b.lineWidth,1)};this.getCanvas=function(){return d},this.getCtx=function(){return e},this.clear=function(){e.clearRect(b.size/-2,b.size/-2,b.size,b.size)},this.draw=function(a){b.scaleColor||b.trackColor?e.getImageData&&e.putImageData?c?e.putImageData(c,0,0):(k(),c=e.getImageData(0,0,b.size*f,b.size*f)):(this.clear(),k()):this.clear(),e.lineCap=b.lineCap;var d;d="function"==typeof b.barColor?b.barColor(a):b.barColor,h(d,b.lineWidth,a/100)}.bind(this),this.animate=function(a,c){var d=Date.now();b.onStart(a,c);var e=function(){var f=Math.min(Date.now()-d,b.animate.duration),g=b.easing(this,f,a,c-a,b.animate.duration);this.draw(g),b.onStep(a,c,g),f>=b.animate.duration?b.onStop(a,c):j(e)}.bind(this);j(e)}.bind(this)},c=function(a,c){var d={barColor:"#ef1e25",trackColor:"#f9f9f9",scaleColor:"#dfe0e0",scaleLength:5,lineCap:"round",lineWidth:3,size:110,rotate:0,animate:{duration:1e3,enabled:!0},easing:function(a,b,c,d,e){return b/=e/2,1>b?d/2*b*b+c:-d/2*(--b*(b-2)-1)+c},onStart:function(){},onStep:function(){},onStop:function(){}};if("undefined"!=typeof b)d.renderer=b;else{if("undefined"==typeof SVGRenderer)throw new Error("Please load either the SVG- or the CanvasRenderer");d.renderer=SVGRenderer}var e={},f=0,g=function(){this.el=a,this.options=e;for(var b in d)d.hasOwnProperty(b)&&(e[b]=c&&"undefined"!=typeof c[b]?c[b]:d[b],"function"==typeof e[b]&&(e[b]=e[b].bind(this)));e.easing="string"==typeof e.easing&&"undefined"!=typeof jQuery&&jQuery.isFunction(jQuery.easing[e.easing])?jQuery.easing[e.easing]:d.easing,"number"==typeof e.animate&&(e.animate={duration:e.animate,enabled:!0}),"boolean"!=typeof e.animate||e.animate||(e.animate={duration:1e3,enabled:e.animate}),this.renderer=new e.renderer(a,e),this.renderer.draw(f),a.dataset&&a.dataset.percent?this.update(parseFloat(a.dataset.percent)):a.getAttribute&&a.getAttribute("data-percent")&&this.update(parseFloat(a.getAttribute("data-percent")))}.bind(this);this.update=function(a){return a=parseFloat(a),e.animate.enabled?this.renderer.animate(f,a):this.renderer.draw(a),f=a,this}.bind(this),this.disableAnimation=function(){return e.animate.enabled=!1,this},this.enableAnimation=function(){return e.animate.enabled=!0,this},g()}});
\ No newline at end of file
/**!
* easyPieChart
* Lightweight plugin to render simple, animated and retina optimized pie charts
*
* @license
* @author Robert Fleischmann <rendro87@gmail.com> (http://robert-fleischmann.de)
* @version 2.1.5
**/
(function(root, factory) {
if(typeof exports === 'object') {
module.exports = factory();
}
else if(typeof define === 'function' && define.amd) {
define([], factory);
}
else {
root['EasyPieChart'] = factory();
}
}(this, function() {
/**
* Renderer to render the chart on a canvas object
* @param {DOMElement} el DOM element to host the canvas (root of the plugin)
* @param {object} options options object of the plugin
*/
var CanvasRenderer = function(el, options) {
var cachedBackground;
var canvas = document.createElement('canvas');
el.appendChild(canvas);
if (typeof(G_vmlCanvasManager) !== 'undefined') {
G_vmlCanvasManager.initElement(canvas);
}
var ctx = canvas.getContext('2d');
canvas.width = canvas.height = options.size;
// canvas on retina devices
var scaleBy = 1;
if (window.devicePixelRatio > 1) {
scaleBy = window.devicePixelRatio;
canvas.style.width = canvas.style.height = [options.size, 'px'].join('');
canvas.width = canvas.height = options.size * scaleBy;
ctx.scale(scaleBy, scaleBy);
}
// move 0,0 coordinates to the center
ctx.translate(options.size / 2, options.size / 2);
// rotate canvas -90deg
ctx.rotate((-1 / 2 + options.rotate / 180) * Math.PI);
var radius = (options.size - options.lineWidth) / 2;
if (options.scaleColor && options.scaleLength) {
radius -= options.scaleLength + 2; // 2 is the distance between scale and bar
}
// IE polyfill for Date
Date.now = Date.now || function() {
return +(new Date());
};
/**
* Draw a circle around the center of the canvas
* @param {strong} color Valid CSS color string
* @param {number} lineWidth Width of the line in px
* @param {number} percent Percentage to draw (float between -1 and 1)
*/
var drawCircle = function(color, lineWidth, percent) {
percent = Math.min(Math.max(-1, percent || 0), 1);
var isNegative = percent <= 0 ? true : false;
ctx.beginPath();
ctx.arc(0, 0, radius, 0, Math.PI * 2 * percent, isNegative);
ctx.strokeStyle = color;
ctx.lineWidth = lineWidth;
ctx.stroke();
};
/**
* Draw the scale of the chart
*/
var drawScale = function() {
var offset;
var length;
ctx.lineWidth = 1;
ctx.fillStyle = options.scaleColor;
ctx.save();
for (var i = 24; i > 0; --i) {
if (i % 6 === 0) {
length = options.scaleLength;
offset = 0;
} else {
length = options.scaleLength * 0.6;
offset = options.scaleLength - length;
}
ctx.fillRect(-options.size/2 + offset, 0, length, 1);
ctx.rotate(Math.PI / 12);
}
ctx.restore();
};
/**
* Request animation frame wrapper with polyfill
* @return {function} Request animation frame method or timeout fallback
*/
var reqAnimationFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
}());
/**
* Draw the background of the plugin including the scale and the track
*/
var drawBackground = function() {
if(options.scaleColor) drawScale();
if(options.trackColor) drawCircle(options.trackColor, options.lineWidth, 1);
};
/**
* Canvas accessor
*/
this.getCanvas = function() {
return canvas;
};
/**
* Canvas 2D context 'ctx' accessor
*/
this.getCtx = function() {
return ctx;
};
/**
* Clear the complete canvas
*/
this.clear = function() {
ctx.clearRect(options.size / -2, options.size / -2, options.size, options.size);
};
/**
* Draw the complete chart
* @param {number} percent Percent shown by the chart between -100 and 100
*/
this.draw = function(percent) {
// do we need to render a background
if (!!options.scaleColor || !!options.trackColor) {
// getImageData and putImageData are supported
if (ctx.getImageData && ctx.putImageData) {
if (!cachedBackground) {
drawBackground();
cachedBackground = ctx.getImageData(0, 0, options.size * scaleBy, options.size * scaleBy);
} else {
ctx.putImageData(cachedBackground, 0, 0);
}
} else {
this.clear();
drawBackground();
}
} else {
this.clear();
}
ctx.lineCap = options.lineCap;
// if barcolor is a function execute it and pass the percent as a value
var color;
if (typeof(options.barColor) === 'function') {
color = options.barColor(percent);
} else {
color = options.barColor;
}
// draw bar
drawCircle(color, options.lineWidth, percent / 100);
}.bind(this);
/**
* Animate from some percent to some other percentage
* @param {number} from Starting percentage
* @param {number} to Final percentage
*/
this.animate = function(from, to) {
var startTime = Date.now();
options.onStart(from, to);
var animation = function() {
var process = Math.min(Date.now() - startTime, options.animate.duration);
var currentValue = options.easing(this, process, from, to - from, options.animate.duration);
this.draw(currentValue);
options.onStep(from, to, currentValue);
if (process >= options.animate.duration) {
options.onStop(from, to);
} else {
reqAnimationFrame(animation);
}
}.bind(this);
reqAnimationFrame(animation);
}.bind(this);
};
var EasyPieChart = function(el, opts) {
var defaultOptions = {
barColor: '#ef1e25',
trackColor: '#f9f9f9',
scaleColor: '#dfe0e0',
scaleLength: 5,
lineCap: 'round',
lineWidth: 3,
size: 110,
rotate: 0,
animate: {
duration: 1000,
enabled: true
},
easing: function (x, t, b, c, d) { // more can be found here: http://gsgd.co.uk/sandbox/jquery/easing/
t = t / (d/2);
if (t < 1) {
return c / 2 * t * t + b;
}
return -c/2 * ((--t)*(t-2) - 1) + b;
},
onStart: function(from, to) {
return;
},
onStep: function(from, to, currentValue) {
return;
},
onStop: function(from, to) {
return;
}
};
// detect present renderer
if (typeof(CanvasRenderer) !== 'undefined') {
defaultOptions.renderer = CanvasRenderer;
} else if (typeof(SVGRenderer) !== 'undefined') {
defaultOptions.renderer = SVGRenderer;
} else {
throw new Error('Please load either the SVG- or the CanvasRenderer');
}
var options = {};
var currentValue = 0;
/**
* Initialize the plugin by creating the options object and initialize rendering
*/
var init = function() {
this.el = el;
this.options = options;
// merge user options into default options
for (var i in defaultOptions) {
if (defaultOptions.hasOwnProperty(i)) {
options[i] = opts && typeof(opts[i]) !== 'undefined' ? opts[i] : defaultOptions[i];
if (typeof(options[i]) === 'function') {
options[i] = options[i].bind(this);
}
}
}
// check for jQuery easing
if (typeof(options.easing) === 'string' && typeof(jQuery) !== 'undefined' && jQuery.isFunction(jQuery.easing[options.easing])) {
options.easing = jQuery.easing[options.easing];
} else {
options.easing = defaultOptions.easing;
}
// process earlier animate option to avoid bc breaks
if (typeof(options.animate) === 'number') {
options.animate = {
duration: options.animate,
enabled: true
};
}
if (typeof(options.animate) === 'boolean' && !options.animate) {
options.animate = {
duration: 1000,
enabled: options.animate
};
}
// create renderer
this.renderer = new options.renderer(el, options);
// initial draw
this.renderer.draw(currentValue);
// initial update
if (el.dataset && el.dataset.percent) {
this.update(parseFloat(el.dataset.percent));
} else if (el.getAttribute && el.getAttribute('data-percent')) {
this.update(parseFloat(el.getAttribute('data-percent')));
}
}.bind(this);
/**
* Update the value of the chart
* @param {number} newValue Number between 0 and 100
* @return {object} Instance of the plugin for method chaining
*/
this.update = function(newValue) {
newValue = parseFloat(newValue);
if (options.animate.enabled) {
this.renderer.animate(currentValue, newValue);
} else {
this.renderer.draw(newValue);
}
currentValue = newValue;
return this;
}.bind(this);
/**
* Disable animation
* @return {object} Instance of the plugin for method chaining
*/
this.disableAnimation = function() {
options.animate.enabled = false;
return this;
};
/**
* Enable animation
* @return {object} Instance of the plugin for method chaining
*/
this.enableAnimation = function() {
options.animate.enabled = true;
return this;
};
init();
};
return EasyPieChart;
}));
/**!
* easyPieChart
* Lightweight plugin to render simple, animated and retina optimized pie charts
*
* @license
* @author Robert Fleischmann <rendro87@gmail.com> (http://robert-fleischmann.de)
* @version 2.1.5
**/
!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define([],b):a.EasyPieChart=b()}(this,function(){var a=function(a,b){var c,d=document.createElement("canvas");a.appendChild(d),"undefined"!=typeof G_vmlCanvasManager&&G_vmlCanvasManager.initElement(d);var e=d.getContext("2d");d.width=d.height=b.size;var f=1;window.devicePixelRatio>1&&(f=window.devicePixelRatio,d.style.width=d.style.height=[b.size,"px"].join(""),d.width=d.height=b.size*f,e.scale(f,f)),e.translate(b.size/2,b.size/2),e.rotate((-0.5+b.rotate/180)*Math.PI);var g=(b.size-b.lineWidth)/2;b.scaleColor&&b.scaleLength&&(g-=b.scaleLength+2),Date.now=Date.now||function(){return+new Date};var h=function(a,b,c){c=Math.min(Math.max(-1,c||0),1);var d=0>=c?!0:!1;e.beginPath(),e.arc(0,0,g,0,2*Math.PI*c,d),e.strokeStyle=a,e.lineWidth=b,e.stroke()},i=function(){var a,c;e.lineWidth=1,e.fillStyle=b.scaleColor,e.save();for(var d=24;d>0;--d)d%6===0?(c=b.scaleLength,a=0):(c=.6*b.scaleLength,a=b.scaleLength-c),e.fillRect(-b.size/2+a,0,c,1),e.rotate(Math.PI/12);e.restore()},j=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}(),k=function(){b.scaleColor&&i(),b.trackColor&&h(b.trackColor,b.lineWidth,1)};this.getCanvas=function(){return d},this.getCtx=function(){return e},this.clear=function(){e.clearRect(b.size/-2,b.size/-2,b.size,b.size)},this.draw=function(a){b.scaleColor||b.trackColor?e.getImageData&&e.putImageData?c?e.putImageData(c,0,0):(k(),c=e.getImageData(0,0,b.size*f,b.size*f)):(this.clear(),k()):this.clear(),e.lineCap=b.lineCap;var d;d="function"==typeof b.barColor?b.barColor(a):b.barColor,h(d,b.lineWidth,a/100)}.bind(this),this.animate=function(a,c){var d=Date.now();b.onStart(a,c);var e=function(){var f=Math.min(Date.now()-d,b.animate.duration),g=b.easing(this,f,a,c-a,b.animate.duration);this.draw(g),b.onStep(a,c,g),f>=b.animate.duration?b.onStop(a,c):j(e)}.bind(this);j(e)}.bind(this)},b=function(b,c){var d={barColor:"#ef1e25",trackColor:"#f9f9f9",scaleColor:"#dfe0e0",scaleLength:5,lineCap:"round",lineWidth:3,size:110,rotate:0,animate:{duration:1e3,enabled:!0},easing:function(a,b,c,d,e){return b/=e/2,1>b?d/2*b*b+c:-d/2*(--b*(b-2)-1)+c},onStart:function(){},onStep:function(){},onStop:function(){}};if("undefined"!=typeof a)d.renderer=a;else{if("undefined"==typeof SVGRenderer)throw new Error("Please load either the SVG- or the CanvasRenderer");d.renderer=SVGRenderer}var e={},f=0,g=function(){this.el=b,this.options=e;for(var a in d)d.hasOwnProperty(a)&&(e[a]=c&&"undefined"!=typeof c[a]?c[a]:d[a],"function"==typeof e[a]&&(e[a]=e[a].bind(this)));e.easing="string"==typeof e.easing&&"undefined"!=typeof jQuery&&jQuery.isFunction(jQuery.easing[e.easing])?jQuery.easing[e.easing]:d.easing,"number"==typeof e.animate&&(e.animate={duration:e.animate,enabled:!0}),"boolean"!=typeof e.animate||e.animate||(e.animate={duration:1e3,enabled:e.animate}),this.renderer=new e.renderer(b,e),this.renderer.draw(f),b.dataset&&b.dataset.percent?this.update(parseFloat(b.dataset.percent)):b.getAttribute&&b.getAttribute("data-percent")&&this.update(parseFloat(b.getAttribute("data-percent")))}.bind(this);this.update=function(a){return a=parseFloat(a),e.animate.enabled?this.renderer.animate(f,a):this.renderer.draw(a),f=a,this}.bind(this),this.disableAnimation=function(){return e.animate.enabled=!1,this},this.enableAnimation=function(){return e.animate.enabled=!0,this},g()};return b});
\ No newline at end of file
/**!
* easyPieChart
* Lightweight plugin to render simple, animated and retina optimized pie charts
*
* @license
* @author Robert Fleischmann <rendro87@gmail.com> (http://robert-fleischmann.de)
* @version 2.1.5
**/
(function(root, factory) {
if(typeof exports === 'object') {
module.exports = factory(require('jquery'));
}
else if(typeof define === 'function' && define.amd) {
define(['jquery'], factory);
}
else {
factory(root.jQuery);
}
}(this, function($) {
/**
* Renderer to render the chart on a canvas object
* @param {DOMElement} el DOM element to host the canvas (root of the plugin)
* @param {object} options options object of the plugin
*/
var CanvasRenderer = function(el, options) {
var cachedBackground;
var canvas = document.createElement('canvas');
el.appendChild(canvas);
if (typeof(G_vmlCanvasManager) !== 'undefined') {
G_vmlCanvasManager.initElement(canvas);
}
var ctx = canvas.getContext('2d');
canvas.width = canvas.height = options.size;
// canvas on retina devices
var scaleBy = 1;
if (window.devicePixelRatio > 1) {
scaleBy = window.devicePixelRatio;
canvas.style.width = canvas.style.height = [options.size, 'px'].join('');
canvas.width = canvas.height = options.size * scaleBy;
ctx.scale(scaleBy, scaleBy);
}
// move 0,0 coordinates to the center
ctx.translate(options.size / 2, options.size / 2);
// rotate canvas -90deg
ctx.rotate((-1 / 2 + options.rotate / 180) * Math.PI);
var radius = (options.size - options.lineWidth) / 2;
if (options.scaleColor && options.scaleLength) {
radius -= options.scaleLength + 2; // 2 is the distance between scale and bar
}
// IE polyfill for Date
Date.now = Date.now || function() {
return +(new Date());
};
/**
* Draw a circle around the center of the canvas
* @param {strong} color Valid CSS color string
* @param {number} lineWidth Width of the line in px
* @param {number} percent Percentage to draw (float between -1 and 1)
*/
var drawCircle = function(color, lineWidth, percent) {
percent = Math.min(Math.max(-1, percent || 0), 1);
var isNegative = percent <= 0 ? true : false;
ctx.beginPath();
ctx.arc(0, 0, radius, 0, Math.PI * 2 * percent, isNegative);
ctx.strokeStyle = color;
ctx.lineWidth = lineWidth;
ctx.stroke();
};
/**
* Draw the scale of the chart
*/
var drawScale = function() {
var offset;
var length;
ctx.lineWidth = 1;
ctx.fillStyle = options.scaleColor;
ctx.save();
for (var i = 24; i > 0; --i) {
if (i % 6 === 0) {
length = options.scaleLength;
offset = 0;
} else {
length = options.scaleLength * 0.6;
offset = options.scaleLength - length;
}
ctx.fillRect(-options.size/2 + offset, 0, length, 1);
ctx.rotate(Math.PI / 12);
}
ctx.restore();
};
/**
* Request animation frame wrapper with polyfill
* @return {function} Request animation frame method or timeout fallback
*/
var reqAnimationFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
}());
/**
* Draw the background of the plugin including the scale and the track
*/
var drawBackground = function() {
if(options.scaleColor) drawScale();
if(options.trackColor) drawCircle(options.trackColor, options.lineWidth, 1);
};
/**
* Canvas accessor
*/
this.getCanvas = function() {
return canvas;
};
/**
* Canvas 2D context 'ctx' accessor
*/
this.getCtx = function() {
return ctx;
};
/**
* Clear the complete canvas
*/
this.clear = function() {
ctx.clearRect(options.size / -2, options.size / -2, options.size, options.size);
};
/**
* Draw the complete chart
* @param {number} percent Percent shown by the chart between -100 and 100
*/
this.draw = function(percent) {
// do we need to render a background
if (!!options.scaleColor || !!options.trackColor) {
// getImageData and putImageData are supported
if (ctx.getImageData && ctx.putImageData) {
if (!cachedBackground) {
drawBackground();
cachedBackground = ctx.getImageData(0, 0, options.size * scaleBy, options.size * scaleBy);
} else {
ctx.putImageData(cachedBackground, 0, 0);
}
} else {
this.clear();
drawBackground();
}
} else {
this.clear();
}
ctx.lineCap = options.lineCap;
// if barcolor is a function execute it and pass the percent as a value
var color;
if (typeof(options.barColor) === 'function') {
color = options.barColor(percent);
} else {
color = options.barColor;
}
// draw bar
drawCircle(color, options.lineWidth, percent / 100);
}.bind(this);
/**
* Animate from some percent to some other percentage
* @param {number} from Starting percentage
* @param {number} to Final percentage
*/
this.animate = function(from, to) {
var startTime = Date.now();
options.onStart(from, to);
var animation = function() {
var process = Math.min(Date.now() - startTime, options.animate.duration);
var currentValue = options.easing(this, process, from, to - from, options.animate.duration);
this.draw(currentValue);
options.onStep(from, to, currentValue);
if (process >= options.animate.duration) {
options.onStop(from, to);
} else {
reqAnimationFrame(animation);
}
}.bind(this);
reqAnimationFrame(animation);
}.bind(this);
};
var EasyPieChart = function(el, opts) {
var defaultOptions = {
barColor: '#ef1e25',
trackColor: '#f9f9f9',
scaleColor: '#dfe0e0',
scaleLength: 5,
lineCap: 'round',
lineWidth: 3,
size: 110,
rotate: 0,
animate: {
duration: 1000,
enabled: true
},
easing: function (x, t, b, c, d) { // more can be found here: http://gsgd.co.uk/sandbox/jquery/easing/
t = t / (d/2);
if (t < 1) {
return c / 2 * t * t + b;
}
return -c/2 * ((--t)*(t-2) - 1) + b;
},
onStart: function(from, to) {
return;
},
onStep: function(from, to, currentValue) {
return;
},
onStop: function(from, to) {
return;
}
};
// detect present renderer
if (typeof(CanvasRenderer) !== 'undefined') {
defaultOptions.renderer = CanvasRenderer;
} else if (typeof(SVGRenderer) !== 'undefined') {
defaultOptions.renderer = SVGRenderer;
} else {
throw new Error('Please load either the SVG- or the CanvasRenderer');
}
var options = {};
var currentValue = 0;
/**
* Initialize the plugin by creating the options object and initialize rendering
*/
var init = function() {
this.el = el;
this.options = options;
// merge user options into default options
for (var i in defaultOptions) {
if (defaultOptions.hasOwnProperty(i)) {
options[i] = opts && typeof(opts[i]) !== 'undefined' ? opts[i] : defaultOptions[i];
if (typeof(options[i]) === 'function') {
options[i] = options[i].bind(this);
}
}
}
// check for jQuery easing
if (typeof(options.easing) === 'string' && typeof(jQuery) !== 'undefined' && jQuery.isFunction(jQuery.easing[options.easing])) {
options.easing = jQuery.easing[options.easing];
} else {
options.easing = defaultOptions.easing;
}
// process earlier animate option to avoid bc breaks
if (typeof(options.animate) === 'number') {
options.animate = {
duration: options.animate,
enabled: true
};
}
if (typeof(options.animate) === 'boolean' && !options.animate) {
options.animate = {
duration: 1000,
enabled: options.animate
};
}
// create renderer
this.renderer = new options.renderer(el, options);
// initial draw
this.renderer.draw(currentValue);
// initial update
if (el.dataset && el.dataset.percent) {
this.update(parseFloat(el.dataset.percent));
} else if (el.getAttribute && el.getAttribute('data-percent')) {
this.update(parseFloat(el.getAttribute('data-percent')));
}
}.bind(this);
/**
* Update the value of the chart
* @param {number} newValue Number between 0 and 100
* @return {object} Instance of the plugin for method chaining
*/
this.update = function(newValue) {
newValue = parseFloat(newValue);
if (options.animate.enabled) {
this.renderer.animate(currentValue, newValue);
} else {
this.renderer.draw(newValue);
}
currentValue = newValue;
return this;
}.bind(this);
/**
* Disable animation
* @return {object} Instance of the plugin for method chaining
*/
this.disableAnimation = function() {
options.animate.enabled = false;
return this;
};
/**
* Enable animation
* @return {object} Instance of the plugin for method chaining
*/
this.enableAnimation = function() {
options.animate.enabled = true;
return this;
};
init();
};
$.fn.easyPieChart = function(options) {
return this.each(function() {
var instanceOptions;
if (!$.data(this, 'easyPieChart')) {
instanceOptions = $.extend({}, options, $(this).data());
$.data(this, 'easyPieChart', new EasyPieChart(this, instanceOptions));
}
});
};
}));
/**!
* easyPieChart
* Lightweight plugin to render simple, animated and retina optimized pie charts
*
* @license
* @author Robert Fleischmann <rendro87@gmail.com> (http://robert-fleischmann.de)
* @version 2.1.5
**/
!function(a,b){"object"==typeof exports?module.exports=b(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],b):b(a.jQuery)}(this,function(a){var b=function(a,b){var c,d=document.createElement("canvas");a.appendChild(d),"undefined"!=typeof G_vmlCanvasManager&&G_vmlCanvasManager.initElement(d);var e=d.getContext("2d");d.width=d.height=b.size;var f=1;window.devicePixelRatio>1&&(f=window.devicePixelRatio,d.style.width=d.style.height=[b.size,"px"].join(""),d.width=d.height=b.size*f,e.scale(f,f)),e.translate(b.size/2,b.size/2),e.rotate((-0.5+b.rotate/180)*Math.PI);var g=(b.size-b.lineWidth)/2;b.scaleColor&&b.scaleLength&&(g-=b.scaleLength+2),Date.now=Date.now||function(){return+new Date};var h=function(a,b,c){c=Math.min(Math.max(-1,c||0),1);var d=0>=c?!0:!1;e.beginPath(),e.arc(0,0,g,0,2*Math.PI*c,d),e.strokeStyle=a,e.lineWidth=b,e.stroke()},i=function(){var a,c;e.lineWidth=1,e.fillStyle=b.scaleColor,e.save();for(var d=24;d>0;--d)d%6===0?(c=b.scaleLength,a=0):(c=.6*b.scaleLength,a=b.scaleLength-c),e.fillRect(-b.size/2+a,0,c,1),e.rotate(Math.PI/12);e.restore()},j=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}(),k=function(){b.scaleColor&&i(),b.trackColor&&h(b.trackColor,b.lineWidth,1)};this.getCanvas=function(){return d},this.getCtx=function(){return e},this.clear=function(){e.clearRect(b.size/-2,b.size/-2,b.size,b.size)},this.draw=function(a){b.scaleColor||b.trackColor?e.getImageData&&e.putImageData?c?e.putImageData(c,0,0):(k(),c=e.getImageData(0,0,b.size*f,b.size*f)):(this.clear(),k()):this.clear(),e.lineCap=b.lineCap;var d;d="function"==typeof b.barColor?b.barColor(a):b.barColor,h(d,b.lineWidth,a/100)}.bind(this),this.animate=function(a,c){var d=Date.now();b.onStart(a,c);var e=function(){var f=Math.min(Date.now()-d,b.animate.duration),g=b.easing(this,f,a,c-a,b.animate.duration);this.draw(g),b.onStep(a,c,g),f>=b.animate.duration?b.onStop(a,c):j(e)}.bind(this);j(e)}.bind(this)},c=function(a,c){var d={barColor:"#ef1e25",trackColor:"#f9f9f9",scaleColor:"#dfe0e0",scaleLength:5,lineCap:"round",lineWidth:3,size:110,rotate:0,animate:{duration:1e3,enabled:!0},easing:function(a,b,c,d,e){return b/=e/2,1>b?d/2*b*b+c:-d/2*(--b*(b-2)-1)+c},onStart:function(){},onStep:function(){},onStop:function(){}};if("undefined"!=typeof b)d.renderer=b;else{if("undefined"==typeof SVGRenderer)throw new Error("Please load either the SVG- or the CanvasRenderer");d.renderer=SVGRenderer}var e={},f=0,g=function(){this.el=a,this.options=e;for(var b in d)d.hasOwnProperty(b)&&(e[b]=c&&"undefined"!=typeof c[b]?c[b]:d[b],"function"==typeof e[b]&&(e[b]=e[b].bind(this)));e.easing="string"==typeof e.easing&&"undefined"!=typeof jQuery&&jQuery.isFunction(jQuery.easing[e.easing])?jQuery.easing[e.easing]:d.easing,"number"==typeof e.animate&&(e.animate={duration:e.animate,enabled:!0}),"boolean"!=typeof e.animate||e.animate||(e.animate={duration:1e3,enabled:e.animate}),this.renderer=new e.renderer(a,e),this.renderer.draw(f),a.dataset&&a.dataset.percent?this.update(parseFloat(a.dataset.percent)):a.getAttribute&&a.getAttribute("data-percent")&&this.update(parseFloat(a.getAttribute("data-percent")))}.bind(this);this.update=function(a){return a=parseFloat(a),e.animate.enabled?this.renderer.animate(f,a):this.renderer.draw(a),f=a,this}.bind(this),this.disableAnimation=function(){return e.animate.enabled=!1,this},this.enableAnimation=function(){return e.animate.enabled=!0,this},g()};a.fn.easyPieChart=function(b){return this.each(function(){var d;a.data(this,"easyPieChart")||(d=a.extend({},b,a(this).data()),a.data(this,"easyPieChart",new c(this,d)))})}});
\ No newline at end of file
// Generated by CoffeeScript 1.4.0
/*
Easy pie chart is a jquery plugin to display simple animated pie charts for only one value
Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
Built on top of the jQuery library (http://jquery.com)
@source: http://github.com/rendro/easy-pie-chart/
@autor: Robert Fleischmann
@version: 1.0.1
Inspired by: http://dribbble.com/shots/631074-Simple-Pie-Charts-II?list=popular&offset=210
Thanks to Philip Thrasher for the jquery plugin boilerplate for coffee script
*/
(function() {
(function($) {
$.easyPieChart = function(el, options) {
var addScaleLine, animateLine, drawLine, easeInOutQuad, renderBackground, renderScale, renderTrack,
_this = this;
this.el = el;
this.$el = $(el);
this.$el.data("easyPieChart", this);
this.init = function() {
var percent;
_this.options = $.extend({}, $.easyPieChart.defaultOptions, options);
percent = parseInt(_this.$el.data('percent'), 10);
_this.percentage = 0;
_this.canvas = $("<canvas width='" + _this.options.size + "' height='" + _this.options.size + "'></canvas>").get(0);
_this.$el.append(_this.canvas);
if (typeof G_vmlCanvasManager !== "undefined" && G_vmlCanvasManager !== null) {
G_vmlCanvasManager.initElement(_this.canvas);
}
_this.ctx = _this.canvas.getContext('2d');
if (window.devicePixelRatio > 1.5) {
$(_this.canvas).css({
width: _this.options.size,
height: _this.options.size
});
_this.canvas.width *= 2;
_this.canvas.height *= 2;
_this.ctx.scale(2, 2);
}
_this.ctx.translate(_this.options.size / 2, _this.options.size / 2);
_this.$el.addClass('easyPieChart');
_this.$el.css({
width: _this.options.size,
height: _this.options.size,
lineHeight: "" + _this.options.size + "px"
});
_this.update(percent);
return _this;
};
this.update = function(percent) {
if (_this.options.animate === false) {
return drawLine(percent);
} else {
return animateLine(_this.percentage, percent);
}
};
renderScale = function() {
var i, _i, _results;
_this.ctx.fillStyle = _this.options.scaleColor;
_this.ctx.lineWidth = 1;
_results = [];
for (i = _i = 0; _i <= 24; i = ++_i) {
_results.push(addScaleLine(i));
}
return _results;
};
addScaleLine = function(i) {
var offset;
offset = i % 6 === 0 ? 0 : _this.options.size * 0.017;
_this.ctx.save();
_this.ctx.rotate(i * Math.PI / 12);
_this.ctx.fillRect(_this.options.size / 2 - offset, 0, -_this.options.size * 0.05 + offset, 1);
return _this.ctx.restore();
};
renderTrack = function() {
var offset;
offset = _this.options.size / 2 - _this.options.lineWidth / 2;
if (_this.options.scaleColor !== false) {
offset -= _this.options.size * 0.08;
}
_this.ctx.beginPath();
_this.ctx.arc(0, 0, offset, 0, Math.PI * 2, true);
_this.ctx.closePath();
_this.ctx.strokeStyle = _this.options.trackColor;
_this.ctx.lineWidth = _this.options.lineWidth;
return _this.ctx.stroke();
};
renderBackground = function() {
if (_this.options.scaleColor !== false) {
renderScale();
}
if (_this.options.trackColor !== false) {
return renderTrack();
}
};
drawLine = function(percent) {
var offset;
renderBackground();
_this.ctx.strokeStyle = $.isFunction(_this.options.barColor) ? _this.options.barColor(percent) : _this.options.barColor;
_this.ctx.lineCap = _this.options.lineCap;
_this.ctx.lineWidth = _this.options.lineWidth;
offset = _this.options.size / 2 - _this.options.lineWidth / 2;
if (_this.options.scaleColor !== false) {
offset -= _this.options.size * 0.08;
}
_this.ctx.save();
_this.ctx.rotate(-Math.PI / 2);
_this.ctx.beginPath();
_this.ctx.arc(0, 0, offset, 0, Math.PI * 2 * percent / 100, false);
_this.ctx.stroke();
return _this.ctx.restore();
};
animateLine = function(from, to) {
var currentStep, fps, steps;
fps = 30;
steps = fps * _this.options.animate / 1000;
currentStep = 0;
_this.options.onStart.call(_this);
_this.percentage = to;
if (_this.animation) {
clearInterval(_this.animation);
_this.animation = false;
}
return _this.animation = setInterval(function() {
_this.ctx.clearRect(-_this.options.size / 2, -_this.options.size / 2, _this.options.size, _this.options.size);
renderBackground.call(_this);
drawLine.call(_this, [easeInOutQuad(currentStep, from, to - from, steps)]);
currentStep++;
if ((currentStep / steps) > 1) {
clearInterval(_this.animation);
_this.animation = false;
return _this.options.onStop.call(_this);
}
}, 1000 / fps);
};
easeInOutQuad = function(t, b, c, d) {
var easeIn, easing;
easeIn = function(t) {
return Math.pow(t, 2);
};
easing = function(t) {
if (t < 1) {
return easeIn(t);
} else {
return 2 - easeIn((t / 2) * -2 + 2);
}
};
t /= d / 2;
return c / 2 * easing(t) + b;
};
return this.init();
};
$.easyPieChart.defaultOptions = {
barColor: '#ef1e25',
trackColor: '#f2f2f2',
scaleColor: '#dfe0e0',
lineCap: 'round',
size: 110,
lineWidth: 3,
animate: false,
onStart: $.noop,
onStop: $.noop
};
$.fn.easyPieChart = function(options) {
return $.each(this, function(i, el) {
var $el;
$el = $(el);
if (!$el.data('easyPieChart')) {
return $el.data('easyPieChart', new $.easyPieChart(el, options));
}
});
};
return void 0;
})(jQuery);
}).call(this);
......@@ -3,9 +3,11 @@
{% block css %}
{% load staticfiles %}
<link rel="stylesheet" href="{% static "css/bootstrap.css" %}">
<link rel="stylesheet" href="{% static "css/bootstrap-theme.min.css" %}">
<link rel="stylesheet" href="{% static "css/morris.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "css/bootstrap.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "css/bootstrap-theme.min.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "css/morris.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "css/jquery.easy-pie-chart.css"%}">
<script src="{% static "js/jquery-1.9.1.min.js"%}"></script>
<script src="{% static "js/raphael-min.js"%}"></script>
......@@ -48,8 +50,6 @@
<div id="hero-donut" style="height: 250px;"></div>
</div>
</div>
</div>
......@@ -74,7 +74,9 @@
hideHover: 'auto',
lineColors: ["#939393",]
});
</script>
<script>
// Morris Donut Chart
Morris.Donut({
......@@ -91,12 +93,6 @@
//colors: ["#30a1ec", "#76bdee"],
formatter: function (y) { return y + "%" }
});
</script>
{% endblock %}
......@@ -24,6 +24,7 @@
<li><a href="/admin/">Admin</a></li>
<li><a href="/contact/">Contact</a></li>
</ul>
</div>
</div>
......@@ -43,7 +44,25 @@
<!-- Place at the end of the document so the pages load faster -->
{% load staticfiles %}
<script src="{% static "js/jquery.min.js" %}"></script>
<script src="{% static "js/jquery-1.9.1.min.js"%}"></script>
<script src="{% static "js/easy/jquery.easypiechart.js"%}"></script>
<script type="text/javascript">
$(function() {
$('.chart').easyPieChart({
//your configuration goes here
size : 50
});
});
</script>
<script src="{% static "js/bootstrap.min.js" %}"></script>
</body>
</html>
......
......@@ -5,6 +5,8 @@
{% load staticfiles %}
<link rel="stylesheet" href="{% static "css/bootstrap.css" %}">
<link rel="stylesheet" href="{% static "css/bootstrap-theme.min.css" %}">
{% endblock %}
......@@ -32,6 +34,8 @@
<h3><a href="/project/{{ project.id }}/corpus/{{corpus.id}}">{{ corpus.title }}</a></h3>
<h4>{{ corpus.subtitle }}</h4>
<p>{{ corpus.language }}, {{ corpus.database}}</p>
<div class="chart" data-percent="73">73%</div>
</div>
{% endfor %}
{% endif %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment