-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotutils.py
More file actions
60 lines (48 loc) · 1.74 KB
/
plotutils.py
File metadata and controls
60 lines (48 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pandas as pd
import destinyPlatform as destiny
import json
import os
import time
import numpy as np
import jinja2
import logging
import sys
from nvd3py import *
FULL_PLOT_HTML_DIRECTORY = os.path.join("blog","content","pages","fullPlots","characterData")
FULL_PLOT_JS_DIRECTORY = os.path.join(FULL_PLOT_HTML_DIRECTORY, "javascripts")
FULL_PLOT_JSON_DIRECTORY = os.path.join(FULL_PLOT_HTML_DIRECTORY, "datafiles")
PLOT_TEMPLATES = "plotTemplates"
jinja2_env = jinja2.Environment(loader=jinja2.FileSystemLoader('plotTemplates'))
def _makeDirectories(path):
if not os.path.isdir(path):
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST:
raise
def writeGraph(graph, htmlTemplate="htmlTemplate.html", author="Giovanni Briggs",
date=None, category='Full Plots', tags=None, extension=".html", url=None):
print(FULL_PLOT_HTML_DIRECTORY)
#make sure all directories are created and ready to go
_makeDirectories(FULL_PLOT_HTML_DIRECTORY)
_makeDirectories(FULL_PLOT_JS_DIRECTORY)
_makeDirectories(FULL_PLOT_JSON_DIRECTORY)
if date is None:
date = time.strftime("%Y-%m-%d")
#write to javascript file
graph.buildcontent()
with open(graph.fullJS, 'w') as f:
f.write(graph.htmlcontent)
#write to html file
template = jinja2_env.get_template(os.path.join(htmlTemplate))
template_values = {
'destinyGraph': graph.__dict__,
'date': date,
'category': category,
'author':author,
'tags': tags,
'url':url
}
output = template.render(template_values)
with open(os.path.join(FULL_PLOT_HTML_DIRECTORY, (graph.name + extension)), 'w') as f:
f.write(output)