ore.models.configuration   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 14
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Configuration.to_dict() 0 10 2
1
from django.db import models
2
import json
3
4
from .graph import Graph
5
6
7
class Configuration(models.Model):
8
9
    """
10
    Class: Project
11
12
    Fields:
13
     {Graph} graph       -
14
     {int}   costs       -
15
    """
16
17
    class Meta:
18
        app_label = 'ore'
19
20
    graph = models.ForeignKey(Graph, related_name='configurations')
21
    costs = models.IntegerField()
22
23
    def to_dict(self):
24
        '''
25
          Returns the specific node configurations in this graph configuration
26
          as JSON dictionary data structure. The keys are node client ID's, so that the
27
          JS code can identify them.
28
        '''
29
        result = {}
30
        for node_conf in self.node_configurations.all():
31
            result[node_conf.node.client_id] = json.loads(node_conf.setting)
32
        return result
33