def test_get_list_of_characteristics(self):
     data = {
         'ProductStructure': [{
             'elementId':
             'parent',
             'name':
             'parent_element',
             'type':
             "FEATURE",
             'additionalData': [],
             'children': [{
                 'elementId': 'child',
                 'name': 'child',
                 'children': [],
                 'additionalData': [],
                 'type': "CHARACTERISTIC"
             }],
         }]
     }
     ps_structure = ProductStructureModel(data)
     assert len(ps_structure.get_list_of_characteristics()) == 1
 def test_is_characteristic(self):
     data = {
         'ProductStructure': [{
             'elementId':
             'parent',
             'name':
             'parent_element',
             'type':
             "FEATURE",
             'additionalData': [],
             'children': [{
                 'elementId': 'child',
                 'name': 'child',
                 'children': [],
                 'additionalData': [],
                 'type': "CHARACTERISTIC"
             }],
         }]
     }
     ps_structure = ProductStructureModel(data)
     assert ps_structure.isCharacteristic('child') == True
     assert ps_structure.isCharacteristic('parent') == False
def generate_unfinished_configurations(fullness=0.3, amount=1000):
    configurations = TinyDB('./evaluation/eval.json').table('CONFIG').all()
    global CONFIGURATIONS_UNFINISHED
    
    characteristics = list(map(lambda x: x.elementId,ProductStructureModel(data).get_list_of_characteristics()))

    CONFIGURATIONS_UNFINISHED = []
    for i in range(amount):
        final_config = configurations[random.randint(0, len(configurations) - 1)]
        codes = list(filter(lambda x: x in characteristics, final_config['configuration']))
        conf_size = math.ceil(len(codes) * fullness)

        unfishied_config = random.sample(codes, conf_size)

        CONFIGURATIONS_UNFINISHED.append(ConfigurationModel({
            "configuration": unfishied_config,
            "variables": []
        }))
    return CONFIGURATIONS_UNFINISHED
product_structure = ProductStructureModel({
    'ProductStructure': [
        {
            'elementId':
            'A',
            'name':
            'parent_element A',
            'type':
            "FEATURE",
            'additionalData': [],
            'children': [{
                'elementId': 'A1',
                'name': 'child A1',
                'children': [],
                'additionalData': [],
                'type': "CHARACTERISTIC"
            }, {
                'elementId': 'A2',
                'name': 'child A2',
                'children': [],
                'additionalData': [],
                'type': "CHARACTERISTIC"
            }],
        },
        {
            'elementId':
            'B',
            'name':
            'parent_element B',
            'type':
            "FEATURE",
            'additionalData': [],
            'children': [{
                'elementId': 'B1',
                'name': 'child B1',
                'children': [],
                'additionalData': [],
                'type': "CHARACTERISTIC"
            }, {
                'elementId': 'B2',
                'name': 'child B2',
                'children': [],
                'additionalData': [],
                'type': "CHARACTERISTIC"
            }],
        },
    ]
})
Example #5
0
 def get_as_objects(self) -> ProductStructureModel:
     return ProductStructureModel(self.get())
from model.product_structure_model import ProductStructureModel
from model.preferences_model import Preferences
from model.configuration_model import ConfigurationModel
from managers.recommendation_manager import SimpleConfigurationMaxSelector
from scoring.scoring_functions import ReduceScoringFunctionFactory
from user_type_mappings import TYPE_ATHLETE, TYPE_CONSUMER, TYPE_ENVIRONMENTALIST, TYPE_OWNER, TYPE_RANDOM
import operator
import time
import numpy as np
import matplotlib.pyplot as pp
import random
import math
import json
with open('./evaluation/product_structure.json') as json_file:
    data = json.load(json_file)
    product_structure = ProductStructureModel(data)

from tinydb import TinyDB


def DB():
    return TinyDB('eval.json')

def DB_CONFIG():
    return DB().table('CONFIG')

def DB_PRODUCT_STRUCTURE():
    return DB().table('PRODUCT_STRUCTURE') 

CONFIGURATIONS_UNFINISHED = []
PREFERENCES_RANDOM_MEMBER = []