Newer
Older
#!/usr/bin/python
# -*- coding: utf-8 -*-
import csv
import collections
import json
from distutils.version import LooseVersion
def get_data(filename):
'''function to read the data form the input csv file to use in the analysis'''
reader = [] # Just in case the file open fails
with open(filename, 'rb') as f:
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
61
62
63
64
65
#returns all the data from the csv file in list form
#f.close() # May need to close the file when done
return list(reader) # only return the reader when you have finished.
your_list = []
your_list += get_data('./scripts/modules-anselm.csv')
your_list += get_data('./scripts/modules-salomon.csv')
your_list += get_data('./scripts/modules-salomon-uv.csv')
#print your_list
#a=[["python/2.8.1",1],["python/2.9.1",2],["python/2.8.1",4],["python/3.0.1",4]]
counts = dict()
for i in your_list:
#print i[0]
#print int(i[1])
counts[i[0]]=counts.get(i[0], 0) + int(i[1])
#print sorted(counts.items())
c=[
"---",
"--A",
"-S-",
"-SA",
"U--",
"U-A",
"US-",
"USA",
]
software = dict()
versions = ''
clusters = ''
prev = ''
for m,i in sorted(counts.items()):
#print m
split = m.split('/')
#print split
if len(split) > 1:
a = split[0]
b = split[1]
if split[0] <> prev:
software[a] = {}
software[a][b] = '`' + c[i] + '`'
prev = a
packages = {}
for m in sorted(software.items(), key=lambda i: i[0].lower()):
packages[m[0]]=sorted(m[1], key=LooseVersion)[len(m[1])-1]