Esempio n. 1
0
def plot_distribution(n_clicks, files_content, nodes_content):
    """Plots the distribution"""
    if files_content is not None and nodes_content is not None:
        filestring = stringify_contents(files_content)
        nodestring = stringify_contents(nodes_content)
        print(nodestring)
        distribution = Distribution.from_strings(nodestring, filestring)
        fig = distribution.get_plotly(output_file=False)
        component = dcc.Graph(id="distribution_chart", figure=fig)
        return component
Esempio n. 2
0
    def test_parsing(self):
        """Test parsing functionality"""
        nodetext = 'node_1 10\nnode_2 100'
        parsed = parse_string(nodetext)
        self.assertEqual(parsed[0], ('node_1', 10))
        self.assertEqual(parsed[1], ('node_2', 100))
        longtext = generate_text(100, 'nodes', upper=100, lower=10)
        parsed = parse_string(longtext)
        nnames, sizes = list(zip(*parsed))
        sizes = np.array(sizes)
        # Check text generator
        self.assertTrue((sizes >= 10).all())
        self.assertTrue((sizes <= 100).all())
        self.assertTrue(all([name.startswith('nodes') for name in nnames]))

        # Check invocation from strings
        dist = Distribution.from_strings(longtext, longtext)

        with tempfile.ScratchDir('.'):
            with open('files.txt', 'w') as f:
                f.write(longtext)
            with open('nodes.txt', 'w') as f:
                f.write(longtext)
            dist = Distribution.from_filenames('nodes.txt', 'files.txt')
Esempio n. 3
0
 def test_large(self):
     """Test some big cases to get an idea of scaling"""
     bigfiles = generate_text(1000000, 'files', upper=100)
     bignodes = generate_text(1000, 'nodes')
     # Takes around 1 min now
     dist = Distribution.from_strings(bignodes, bigfiles)