modules-matrix.py 2 KB
Newer Older
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
import csv
David Hrbáč's avatar
David Hrbáč committed
4
import collections
5
from distutils.version import LooseVersion
6 7 8 9 10

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:
Lukáš Krupčík's avatar
push  
Lukáš Krupčík committed
11
        reader = csv.reader(f,delimiter=',')
12 13 14 15 16
        #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 = []
David Hrbáč's avatar
David Hrbáč committed
17 18 19
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')
20 21
#print your_list

David Hrbáč's avatar
David Hrbáč committed
22
#a=[["python/2.8.1",1],["python/2.9.1",2],["python/2.8.1",4],["python/3.0.1",4]]
23 24 25 26 27 28
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])

David Hrbáč's avatar
David Hrbáč committed
29
#print sorted(counts.items())
30 31 32 33 34 35 36 37 38 39 40 41

c=[
"---",
"--A",
"-S-",
"-SA",
"U--",
"U-A",
"US-",
"USA",
]

David Hrbáč's avatar
David Hrbáč committed
42
print '!!! Hint "Cluster Acronyms"'
David Hrbáč's avatar
David Hrbáč committed
43
print '    A - Anselm • S - Salomon • U - uv1 at Salomon'
44
print
David Hrbáč's avatar
David Hrbáč committed
45
print '| Module </br><input id="searchInput" placeholder="🔍 Filter" style="width: 8rem; border-radius: 0.2rem; color: black; padding-left: .2rem;"> | Versions | Clusters |'
David Hrbáč's avatar
David Hrbáč committed
46
print "| ------ | -------- | -------- |"
47

David Hrbáč's avatar
David Hrbáč committed
48 49 50 51
software = dict()
versions = ''
clusters = ''
prev = ''
David Hrbáč's avatar
David Hrbáč committed
52 53

for m,i in sorted(counts.items()):
David Hrbáč's avatar
David Hrbáč committed
54
  #print m
David Hrbáč's avatar
David Hrbáč committed
55
  split =  m.split('/')
David Hrbáč's avatar
David Hrbáč committed
56
  #print split
David Hrbáč's avatar
David Hrbáč committed
57 58 59 60 61
  if len(split) > 1:
    a = split[0]
    b = split[1]
    if split[0] <> prev:
      software[a] = {}
62
    software[a][b] = '`' + c[i] + '`'
David Hrbáč's avatar
David Hrbáč committed
63
    prev = a
64

David Hrbáč's avatar
David Hrbáč committed
65 66
#print software.items()

67
for m in sorted(software.items(), key=lambda i: i[0].lower()):
David Hrbáč's avatar
David Hrbáč committed
68
  software = m[0]
69 70 71 72 73 74
  versions = []
  clusters = []
  for key in sorted(m[1], key=LooseVersion ):
    versions.append(key)
    clusters.append(m[1][key])
  print "| %s | %s | %s |" % (software, '</br>'.join(versions), '</br>'.join(clusters))
75 76 77

print
print '---8<--- "modules_matrix_search.md"'