Skip to content
Snippets Groups Projects
modules-matrix.py 2.59 KiB
Newer Older
  • Learn to ignore specific revisions
  • # -*- coding: utf-8 -*-
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    import collections
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    import itertools
    import re
    
    
    from distutils.version import LooseVersion
    
    David Hrbáč's avatar
    David Hrbáč committed
    
    
    def get_data(filename):
        '''function to read the data form the input csv file to use in the analysis'''
    
    David Hrbáč's avatar
    David Hrbáč committed
        reader = []  # Just in case the file open fails
    
        with open(filename, 'rb') as f:
    
    David Hrbáč's avatar
    David Hrbáč committed
            reader = csv.reader(f, delimiter=',')
            # 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 = []
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    your_list += get_data('./scripts/anselm.csv')
    your_list += get_data('./scripts/salomon.csv')
    your_list += get_data('./scripts/uv2000.csv')
    your_list += get_data('./scripts/phi.csv')
    your_list += get_data('./scripts/dgx.csv')
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    your_list += get_data('./scripts/barbora.csv')
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    print your_list
    
    
    counts = dict()
    for i in your_list:
    
    David Hrbáč's avatar
    David Hrbáč committed
        # print i[0]
        # print int(i[1])
        counts[i[0]] = counts.get(i[0], 0) + int(i[1])
    
    #     1    2    4    8    16   32
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    l = ['A', 'S', 'U', 'P', 'D', 'B']
    c = []
    mask = ''.join(reversed(l))
    from itertools import product
    for bits in product([0, 1], repeat=len(l)):
        s = "".join(str(bit) for bit in bits)
        ns = ""
        for i in range(len(s)):
            if s[i] == "1":
                ns += mask[i]
            else:
                ns += "-"
        c.append(ns)
    
    print '!!! Hint "Cluster Acronyms"'
    
    David Hrbáč's avatar
    David Hrbáč committed
    print '    ```'
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    print '    B D P U S A'
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    print '    | | | | | |'
    print '    | | | | | +----> Anselm'
    print '    | | | | +------> Salomon'
    print '    | | | +--------> UV2000'
    print '    | | +----------> Phi'
    print '    | +------------> DGX-2'
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    print '    +--------------> Barbora'
    
    David Hrbáč's avatar
    David Hrbáč committed
    print '    ```'
    
    David Hrbáč's avatar
    David Hrbáč committed
    print '| Module </br><form><input id="searchInput" placeholder="🔍 Filter" style="width: 8rem; border-radius: 0.2rem; color: black; padding-left: .2rem;"></form> | Versions | Clusters |'
    
    David Hrbáč's avatar
    David Hrbáč committed
    print "| ------ | -------- | -------- |"
    
    David Hrbáč's avatar
    David Hrbáč committed
    software = dict()
    versions = ''
    clusters = ''
    prev = ''
    
    David Hrbáč's avatar
    David Hrbáč committed
    for m, i in sorted(counts.items()):
        #  print m
        split = m.split('/')
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    #  print split
    
    David Hrbáč's avatar
    David Hrbáč committed
        if len(split) > 1:
            a = split[0]
            b = split[1]
            if split[0] <> prev:
                software[a] = {}
            software[a][b] = '`' + c[i] + '`'
            prev = a
    
    for m in sorted(software.items(), key=lambda i: i[0].lower()):
    
    David Hrbáč's avatar
    David Hrbáč committed
        software = m[0]
        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))
    
    
    print
    print '---8<--- "modules_matrix_search.md"'