summaryrefslogtreecommitdiff
path: root/tools/sage_csv_to_sage_json.py
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2015-02-03 17:00:47 +0200
committerLV-426 <lv-426@taproot.org.il>2015-02-03 17:00:47 +0200
commit57bcbce024d6f5832ee7ae2e825d3e34a53c6ed5 (patch)
tree45a0070c7b04f2849fe1d30b77fe5d8ad24ba546 /tools/sage_csv_to_sage_json.py
parent6df92621072e7617f63d2f111369ab96d1af0b21 (diff)
mv sage code artifacts under domain/sage
Diffstat (limited to 'tools/sage_csv_to_sage_json.py')
-rwxr-xr-xtools/sage_csv_to_sage_json.py78
1 files changed, 0 insertions, 78 deletions
diff --git a/tools/sage_csv_to_sage_json.py b/tools/sage_csv_to_sage_json.py
deleted file mode 100755
index b89670ab..00000000
--- a/tools/sage_csv_to_sage_json.py
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/env python
-
-"""
-Convert sage.csv to a loadable file. Here is our current 'file format':
-
-json dictionary with two keys:
-'nodes' is a list of dictionaries, each containing
-'state': 'perm' (should not be required, try without it)
-'id': must be unique
-'name': display only (will be used as id if it is missing, true that?)
-'type': for gannt should be 'deliverable'
-'start': a date for 'deliverable' typed nodes
-'end': a date for 'deliverable' typed nodes
-'status': one of 'done', 'current', 'waiting' for 'deliverable' type
-
-'links is a list of dictionaries with mandatory keys:
-'name'
-'source': id (string)
-'target' id (string)
-"""
-import json
-import csv
-import random
-from datetime import datetime, timedelta
-from time import mktime
-
-class MyEncoder(json.JSONEncoder):
-
- def default(self, obj):
- if isinstance(obj, datetime):
- return int(mktime(obj.timetuple()))
- return json.JSONEncoder.default(self, obj)
-
-def write_json(output_filename, nodes, links):
- seen_ids = set()
- assert(type(nodes) == list)
- assert(type(links) == list)
- for node in nodes:
- assert(type(node) == dict)
- assert('id' in node)
- assert(node['id'] not in seen_ids)
- seen_ids.add(node['id'])
- assert('name' in node)
- for link in links:
- assert(type(link) == dict)
- assert('name' in link)
- assert('source' in link)
- assert('target' in link)
- with open(output_filename, 'w+') as fd:
-
- json.dump({'nodes': nodes, 'links':links}, fd,
- cls=MyEncoder)
-
-def read_sage_csv():
- week = timedelta(days=7)
- day = timedelta(days=1)
- all_start = datetime(year=2018, month=1, day=1)
- lines = list(csv.reader(open('sage.csv')))
- assert(['id', 'name', 'dependent on'] == lines[0])
- del lines[0]
- nodes = [{'id': num, 'name': desc,
- 'type': 'deliverable',
- 'start': all_start + week * i,
- 'end': all_start + week * i + day * (((i * 33) % 17) + 1),
- 'status': random.choice(['unknown', 'done', 'current', 'waiting']),
- } for i, (num, desc, _) in enumerate(lines)]
- links = []
- for num, desc, deps in lines:
- deps = deps.split(',')
- if len(deps) == 0:
- continue
- for dep in deps:
- links.append({'source': num, 'target': dep, 'name': 'depends on'})
- return nodes, links
-
-if __name__ == '__main__':
- nodes, links = read_sage_csv()
- write_json('sage.json', nodes, links)