def setUp(self): super().setUp() # create another activitygroup ag_f = ActivityGroupFactory(keyflow=self.keyflow, name='Construction', code='F') ActivityGroupFactory(keyflow=self.keyflow, name='Some stuff, no idea', code='G') ActivityGroupFactory(keyflow=self.keyflow, name='Other', code='E') ActivityGroupFactory(keyflow=self.keyflow, name='Export', code='WE') ActivityGroupFactory(keyflow=self.keyflow, name='Import', code='R') af = ActivityFactory(activitygroup=ag_f, name='should_be_updated', nace='4110') ActivityFactory(activitygroup=ag_f, name='Collection of non-hazardous waste', nace='E-3811') ActivityFactory(activitygroup=ag_f, name='Collection of hazardous waste', nace='E-3812') ActivityFactory(activitygroup=ag_f, name='shouldnt_be_updated', nace='F-007') ActorFactory(activity=af, BvDid='NL000000029386') ActorFactory(activity=af, BvDid='NL32063450') ActorFactory(activity=af, BvDid='NL123')
def setUp(self): super().setUp() self.activitygroup1 = ActivityGroupFactory(name='MyGroup', keyflow=self.kic) self.activitygroup2 = ActivityGroupFactory(name='AnotherGroup', keyflow=self.kic) self.activity1 = ActivityFactory(nace='NACE1', activitygroup=self.activitygroup1) self.activity2 = ActivityFactory(nace='NACE2', activitygroup=self.activitygroup1) self.activity3 = ActivityFactory(nace='NACE3', activitygroup=self.activitygroup1) self.activity4 = ActivityFactory(nace='NACE4', activitygroup=self.activitygroup2)
def setUp(self): super().setUp() # create another activitygroup ag = ActivityGroupFactory(keyflow=self.keyflow, name='A', code='A') af = ActivityFactory(activitygroup=ag, name='B', nace='123') ac_1 = ActorFactory(activity=af, BvDid='WK036306') ac_2 = ActorFactory(activity=af, BvDid='WK036307') ActorFactory(activity=af, BvDid='WK036308') ActorFactory(activity=af, BvDid='WK036309') ac_3 = ActorFactory(activity=af, BvDid='NL59307803') self.composition = CompositionFactory(name='RES @Urbanisation lvl 1') mat1 = MaterialFactory() mat2 = MaterialFactory() ProductFractionFactory(composition=self.composition, material=mat1, publication=None) ProductFractionFactory(composition=self.composition, material=mat2, publication=None) a = PublicationFactory(citekey='cbs2018', title='sth') PublicationInCasestudyFactory(casestudy=self.casestudy, publication=a) Actor2ActorFactory(origin=ac_1, destination=ac_2, keyflow=self.keyflow) Actor2ActorFactory(origin=ac_1, destination=ac_3, keyflow=self.keyflow)
def setUp(self): super().setUp() self.kic_obj = KeyflowInCasestudyFactory(id=self.keyflowincasestudy, casestudy=self.uic.casestudy, keyflow__id=self.keyflow) self.mat_obj_1 = MaterialFactory(id=self.material_1, keyflow=self.kic_obj) self.mat_obj_2 = MaterialFactory(id=self.material_2, keyflow=self.kic_obj) self.comp1 = CompositionFactory(name='composition1', nace='nace1') self.comp2 = CompositionFactory(name='composition2', nace='nace2') self.activitygroup1 = ActivityGroupFactory(keyflow=self.kic_obj) self.activity1 = ActivityFactory(activitygroup=self.activitygroup1) self.actor1 = ActorFactory(id=self.actor1id, activity=self.activity1) self.activitygroup2 = ActivityGroupFactory(keyflow=self.kic_obj) self.activity2 = ActivityFactory(activitygroup=self.activitygroup2) self.actor2 = ActorFactory(id=self.actor2id, activity=self.activity2) self.actor3 = ActorFactory(activity=self.activity2) self.act2act1 = Actor2ActorFactory( id=self.actor2actor1, origin=self.actor1, destination=self.actor2, keyflow=self.kic_obj, composition=self.comp1, ) self.act2act2 = Actor2ActorFactory( id=self.actor2actor2, origin=self.actor2, destination=self.actor3, keyflow=self.kic_obj, composition=self.comp2, ) self.actorstock1 = ActorStockFactory(id=self.actorstock, keyflow=self.kic_obj, origin=self.actor1) self.actorstock2 = ActorStockFactory(id=self.actorstock2, keyflow=self.kic_obj, origin=self.actor2) self.obj = self.actorstock1
def setUpClass(cls): super().setUpClass() # Create a solution with 3 parts 2 questions cls.solution = SolutionFactory() question_1 = ImplementationQuestionFactory( question="What is the answer to life, the universe and everything?", select_values='0.0,3.14,42,1234.4321', solution=cls.solution) question_2 = ImplementationQuestionFactory(question="What is 1 + 1?", min_value=1, max_value=1000, step=1, solution=cls.solution) possible_implementation_area_1 = PossibleImplementationAreaFactory( solution=cls.solution, geom=MultiPolygon( Polygon(((0.0, 0.0), (0.0, 20.0), (56.0, 20.0), (56.0, 0.0), (0.0, 0.0)))), question=("")) possible_implementation_area_2 = PossibleImplementationAreaFactory( solution=cls.solution, geom=MultiPolygon( Polygon(((0.0, 0.0), (0.0, 20.0), (56.0, 20.0), (56.0, 0.0), (0.0, 0.0)))), question=("")) part_1 = SolutionPartFactory(solution=cls.solution, question=question_1, a=0, b=1) part_2 = SolutionPartFactory(solution=cls.solution, question=question_2) # new target with new actors target_activity = ActivityFactory(name='target_activity') for i in range(3): ActorFactory(activity=target_activity) new_target = FlowReferenceFactory( destination_activity=target_activity, destination_area=possible_implementation_area_1) part_new_flow = SolutionPartFactory(solution=cls.solution, question=question_1, flow_changes=new_target)
def create_actors(self, n_actors=10000): activity_names = [ 'production', 'recycling', 'consumption', ] self.activities = {} for activity_name in activity_names: self.activities[activity_name] = ActivityFactory( name=activity_name, activitygroup__keyflow=self.kic) activities = np.random.choice(list(self.activities.values()), n_actors) actors = [ Actor( activity=activities[i], name=['Actor_{}'.format(i)], ) for i in range(n_actors) ] Actor.objects.bulk_create(actors)
def setUpClass(cls): super().setUpClass() cls.keyflow = KeyflowInCasestudyFactory(id=2) cls.pub = PublicationInCasestudyFactory( casestudy=cls.keyflow.casestudy) ## Materials ## bread = MaterialFactory(name='bread', keyflow=cls.keyflow) beer = MaterialFactory(name='beer', keyflow=cls.keyflow) barley = MaterialFactory(name='barley', keyflow=cls.keyflow) sludge = MaterialFactory(name='sludge', keyflow=cls.keyflow) other_waste = MaterialFactory(name='other waste', keyflow=cls.keyflow) ## Processes ## dummy_process = ProcessFactory(name='process') ## Activities and Activity groups ## group_A = ActivityGroupFactory(name='A', code='A', keyflow=cls.keyflow) group_C = ActivityGroupFactory(name='C', code='C', keyflow=cls.keyflow) brewing_activity = ActivityFactory(name='Brewery', nace='A-0000', activitygroup=group_A) household_activity = ActivityFactory(name='Household', nace='A-0001', activitygroup=group_A) digester_activity = ActivityFactory(name='Digester', nace='A-0002', activitygroup=group_A) supermarket_activity = ActivityFactory(name='Supermarket', nace='A-0003', activitygroup=group_A) farming_activity = ActivityFactory(name='Farming', nace='C-0000', activitygroup=group_C) inciterator_activity = ActivityFactory(name='Incineration', nace='C-0001', activitygroup=group_C) ## Actors ## # random households for i in range(100): ActorFactory(name='household{}'.format(i), activity=household_activity) # random supermarkets for i in range(10): ActorFactory(name='supermarket{}'.format(i), activity=supermarket_activity) # random farms for i in range(2): ActorFactory(name='farm{}'.format(i), activity=farming_activity) cls.brewery_1 = ActorFactory(name='brewery_1', activity=brewing_activity) cls.brewery_2 = ActorFactory(name='brewery_2', activity=brewing_activity) digester = ActorFactory(name='digester Amsterdam', activity=digester_activity) incinerator = ActorFactory(name='incinerator Amsterdam', activity=inciterator_activity) ## status quo flows ## households = Actor.objects.filter(activity=household_activity) farms = Actor.objects.filter(activity=farming_activity) breweries = Actor.objects.filter(activity=brewing_activity) supermarkets = Actor.objects.filter(activity=supermarket_activity) input_digester = 1000 / len(households) input_incinerator_bread = 500 / len(households) input_incinerator_other = 1500 / len(households) input_brewery_barley = 900 / len(farms) input_supermarket_beer = 4000 / (len(supermarkets) * len(breweries)) # B: or whats with the FractionFlows? for i, household in enumerate(households): FractionFlowFactory(origin=household, destination=digester, material=bread, amount=input_digester, keyflow=cls.keyflow) for i, household in enumerate(households): FractionFlowFactory(origin=household, destination=incinerator, material=bread, amount=input_incinerator_bread, keyflow=cls.keyflow) FractionFlowFactory(origin=household, destination=incinerator, material=other_waste, amount=input_incinerator_other, keyflow=cls.keyflow) for i, farm in enumerate(farms): brewery = breweries[i] FractionFlowFactory(origin=farm, destination=brewery, material=barley, amount=input_brewery_barley, keyflow=cls.keyflow) for supermarket in supermarkets: for brewery in breweries: FractionFlowFactory(origin=brewery, destination=supermarket, material=beer, amount=input_supermarket_beer, keyflow=cls.keyflow) for brewery in breweries: FractionFlowFactory(origin=brewery, destination=digester, material=sludge, amount=1000, keyflow=cls.keyflow)
def setUp(self): super().setUp() self.obj = ActivityFactory( activitygroup__keyflow__casestudy=self.uic.casestudy, activitygroup__keyflow=self.kic, activitygroup__id=self.activitygroup)
def setUp(self): super().setUp() self.casestudy = CaseStudyFactory(name=self.csname) self.kic_obj = KeyflowInCasestudyFactory(id=self.keyflowincasestudy, casestudy=self.casestudy, keyflow__id=self.keyflow_id) self.activitygroup1 = ActivityGroupFactory(keyflow=self.kic_obj) self.activity1 = ActivityFactory(activitygroup=self.activitygroup1) self.actor1 = ActorFactory(id=self.actor1id, activity=self.activity1) self.activitygroup2 = ActivityGroupFactory(keyflow=self.kic_obj) self.activity2 = ActivityFactory(activitygroup=self.activitygroup2) self.actor2 = ActorFactory(id=self.actor2id, activity=self.activity2) self.activitygroup3 = ActivityGroupFactory(keyflow=self.kic_obj) self.activity3 = ActivityFactory(activitygroup=self.activitygroup3) self.actor3 = ActorFactory(id=self.actor3id, activity=self.activity3) self.comp1 = CompositionFactory(name='composition1', nace='nace1') self.comp2 = CompositionFactory(name='composition2', nace='nace2') self.mat_obj_1 = MaterialFactory(id=self.material_1, keyflow=self.kic_obj, parent=None) self.mat_obj_2 = MaterialFactory(id=self.material_2, keyflow=self.kic_obj, parent=self.mat_obj_1) self.publicationic = PublicationInCasestudyFactory() # flow attributes #self.process = ProcessFactory(name='test-process') self.fractionflow1 = FractionFlowFactory( flow_id=self.flowid1, #process=self.process, stock=None, to_stock=False, origin=self.actor1, destination=self.actor2, material=self.mat_obj_1, nace=self.comp1.nace, composition_name=self.comp1.name, publication=self.publicationic, keyflow=self.kic_obj, amount=1.0) self.fractionflow2 = FractionFlowFactory( flow_id=self.flowid2, stock=None, to_stock=False, origin=self.actor2, destination=self.actor3, material=self.mat_obj_2, nace=self.comp1.nace, composition_name=self.comp1.name, publication=self.publicationic, keyflow=self.kic_obj, amount=1.0) self.fractionflow3 = FractionFlowFactory( flow_id=self.flowid3, stock=None, to_stock=False, origin=self.actor2, destination=self.actor3, material=self.mat_obj_1, nace=self.comp2.nace, composition_name=self.comp2.name, publication=self.publicationic, keyflow=self.kic_obj, amount=1.0)
def setUpClass(cls): super().setUpClass() ### Modeling the FUNGUS solution and the status quo it is based on ### cls.keyflow = KeyflowInCasestudyFactory() ## Materials ## dummy_mat_1 = MaterialFactory(keyflow=cls.keyflow) dummy_mat_2 = MaterialFactory(keyflow=cls.keyflow) wool = MaterialFactory(name='wool insulation', keyflow=cls.keyflow) fungus = MaterialFactory(name='fungus insulation', keyflow=cls.keyflow) # no idea about the processes, but the process of wool-insulation flow # to E-3821 is supposed to be different to the fungus-insulation one dummy_process = ProcessFactory(name='process') compost = ProcessFactory(name='compost') ## Activities and Activity groups ## group_A = ActivityGroupFactory(name='A', code='A', keyflow=cls.keyflow) group_C = ActivityGroupFactory(name='C', code='C', keyflow=cls.keyflow) group_E = ActivityGroupFactory(name='E', code='E', keyflow=cls.keyflow) group_F = ActivityGroupFactory(name='F', code='F', keyflow=cls.keyflow) group_V = ActivityGroupFactory(name='V', code='V', keyflow=cls.keyflow) dummy_group = ActivityGroupFactory(keyflow=cls.keyflow) growing_activity = ActivityFactory( name='A-0116 Growing of fibre crops', nace='A-0116', activitygroup=group_A) manufacture_activity = ActivityFactory( name='C-2399 Manufacture of non-metallic mineral products', nace='C-2399', activitygroup=group_C) collection_activity = ActivityFactory( name='E-3819 Collection of non-hazardous waste', nace='E-3819', activitygroup=group_E) treatment_activity = ActivityFactory( name='E-3821 Treatment and disposal of non-hazardous waste', nace='E-3821', activitygroup=group_E) building_activity = ActivityFactory( name='F-4110 Development of building projects', nace='F-4110', activitygroup=group_E) consumption_activity = ActivityFactory( name='V-0000 Consumption in households', nace='V-0000', activitygroup=group_V) dummy_activity_1 = ActivityFactory(activitygroup=dummy_group) dummy_activity_2 = ActivityFactory(activitygroup=dummy_group) ## Actors ## # random households for i in range(100): ActorFactory(name='household{}'.format(i), activity=consumption_activity) for i in range(2): building_dev = ActorFactory(name='buildingdev{}'.format(i), activity=building_activity) # this activity is set as spatial choice in the following solution # parts -> they have to be geolocated (just putting it somewhere) # Note CF: geolocate the other models as well? location = AdministrativeLocationFactory(actor=building_dev, geom=Point(x=5, y=52)) collection_insulation = ActorFactory(name='collection', activity=collection_activity) manufacturer = ActorFactory(name='manufacturer'.format(i), activity=manufacture_activity) # put some dummy actors into the dummy activities for i in range(10): ActorFactory(activity=dummy_activity_1) ActorFactory(activity=dummy_activity_2) treatment_insulation = ActorFactory(name='disposal', activity=treatment_activity) cls.treatment_compost = ActorFactory(name='compost', activity=treatment_activity) # putting the fungus farms into "growing fibre crops" lacking better # knowledge fungus_input = ActorFactory(name='chungus', activity=growing_activity) cls.fungus_farm_1 = ActorFactory(name='fungus1', activity=growing_activity) cls.fungus_farm_2 = ActorFactory(name='fungus2', activity=growing_activity) ## status quo flows and stocks ## # making stuff up going into the fungus farm FractionFlowFactory(origin=fungus_input, destination=cls.fungus_farm_1, material=dummy_mat_1, amount=20) FractionFlowFactory(origin=fungus_input, destination=cls.fungus_farm_2, material=dummy_mat_2, amount=10) # fungus stock to possibly derive from # (Note CF: is there a stock? better: put the output to the treatment) FractionFlowFactory(origin=cls.fungus_farm_1, material=fungus, amount=10) FractionFlowFactory(origin=cls.fungus_farm_2, material=fungus, amount=10) # (Note CF: set stocks as affected flows?) households = Actor.objects.filter(activity=consumption_activity) # every household gets same share of 200,000 t/y activity stock stock_share = 200000 / len(households) # Note CF: no idea how much should go in per year input_share = 10 / len(households) builders = Actor.objects.filter(activity=building_activity) step = len(households) / len(builders) # household stock and input for i, household in enumerate(households): # stock FractionFlowFactory(origin=household, material=wool, amount=stock_share) # equally distribute the inputs from the building developers builder = builders[int(i / step)] FractionFlowFactory(origin=builder, destination=household, material=wool, amount=input_share) input_share = 5 / len(builders) # Note CF: how much goes in? # inputs and outputs of builders for builder in builders: # from manufacturer FractionFlowFactory(origin=manufacturer, destination=builder, material=wool, amount=input_share) # to collection FractionFlowFactory(origin=builder, destination=collection_insulation, material=wool, amount=1) # to treatment FractionFlowFactory(origin=builder, destination=treatment_insulation, material=wool, amount=3) # collection to treatment FractionFlowFactory(origin=collection_insulation, destination=treatment_insulation, material=wool, amount=2) # manufacturer to treatment FractionFlowFactory(origin=manufacturer, destination=treatment_insulation, material=wool, amount=2) ## solution definition ## cls.solution = SolutionFactory(name='Fungus Isolation') cls.fungus_question = ImplementationQuestionFactory( question=("How many tonnes per year of fungus should be used as " "insulation material when developing new " "living quarters?"), solution=cls.solution, min_value=0, is_absolute=True # Note CF: is it? ) cls.possible_implementation_area = PossibleImplementationAreaFactory( solution=cls.solution, geom=MultiPolygon( Polygon(((0.0, 0.0), (0.0, 20.0), (56.0, 20.0), (56.0, 0.0), (0.0, 0.0)))), question=("Where are the facilities for composting " "the fungus located?")) ## solution parts ## # the new flow based on flows from c-2399 to f-4110 # Note CF: optional it could also be derived from flows out of the farms implementation = FlowReferenceFactory( origin_activity=manufacture_activity, destination_activity=building_activity, material=wool) shift = FlowReferenceFactory(origin_activity=growing_activity, material=fungus) cls.new_fungus_insulation = SolutionPartFactory( solution=cls.solution, question=cls.fungus_question, flow_reference=implementation, flow_changes=shift, scheme=Scheme.SHIFTORIGIN, a=1, b=0, priority=1) # the new flow based on flows from c-2399 to f-4110 # Note CF: optional it could also be derived from flows out of the farms implementation = FlowReferenceFactory( origin_activity=consumption_activity, destination_activity=None, process=dummy_process, material=wool) # origin actually stays the same but there is no way to shift without # referring to either new destination or origin shift = FlowReferenceFactory(origin_activity=consumption_activity, material=fungus) new_fungus_stock = SolutionPartFactory(solution=cls.solution, question=cls.fungus_question, flow_reference=implementation, flow_changes=shift, scheme=Scheme.SHIFTORIGIN, a=1, b=0, priority=2) # new flow from F-4110 development to E-3821 treatment # Note CF: deriving it from existing F4110 to E3821, just guessing implementation = FlowReferenceFactory( origin_activity=building_activity, destination_activity=treatment_activity, material=wool, process=dummy_process) # actually both activities stay the same shift = FlowReferenceFactory( origin_activity=building_activity, destination_activity=treatment_activity, material=fungus, process=compost, destination_area=cls.possible_implementation_area) cls.new_building_disposal = SolutionPartFactory( solution=cls.solution, # Note CF: i guess we need different numbers than asked for in this # question, or do we even need a question?? question=cls.fungus_question, flow_reference=implementation, flow_changes=shift, scheme=Scheme.SHIFTDESTINATION, a=1, b=0, priority=3) # new flow from fungus farms to E-3821 treatment # Note CF: most likely this should already be modelled in the status quo # deriving it from fungus stock implementation = FlowReferenceFactory(origin_activity=growing_activity, destination_activity=None, process=compost, material=fungus) # origin actually stays the same but there is no way to shift without # referring to either new destination or origin shift = FlowReferenceFactory( destination_activity=treatment_activity, destination_area=cls.possible_implementation_area, material=fungus) # Note CF: reduce existing implementation flow? new_fungus_disposal = SolutionPartFactory( solution=cls.solution, # Note CF: is there a question??? question=None, flow_reference=implementation, flow_changes=shift, scheme=Scheme.SHIFTDESTINATION, a=1, b=0, priority=4) ## affected flows ## # Note CF: poor pull leader has to define the affected flows for # every part, just taking the same ones for all parts # (marking the implementation flows as well, i guess that doesn't matter) # B: who cares about the pull leader?! parts = [ cls.new_fungus_insulation, new_fungus_stock, cls.new_building_disposal, new_fungus_disposal ] for part in parts: # F-4110 to V-0000 AffectedFlow(origin_activity=building_activity, destination_activity=consumption_activity, material=wool, solution_part=part) # Note CF: insulation stock of V-0000 affected as well? # inputs of fungus farm, origin and destination are in same activity # Note CF: might not be this way in reality, maybe inputs come from # different activity? stock missing AffectedFlow(origin_activity=growing_activity, destination_activity=growing_activity, material=dummy_mat_1, solution_part=part) AffectedFlow(origin_activity=growing_activity, destination_activity=growing_activity, material=dummy_mat_2, solution_part=part) # F-4110 to E-3821 AffectedFlow(origin_activity=building_activity, destination_activity=treatment_activity, material=wool, solution_part=part) # F-4110 to E-3819 AffectedFlow(origin_activity=building_activity, destination_activity=collection_activity, material=wool, solution_part=part) # C-2399 to F-4110 AffectedFlow(origin_activity=manufacture_activity, destination_activity=building_activity, material=wool, solution_part=part) # E-3819 to E-3821 AffectedFlow(origin_activity=collection_activity, destination_activity=treatment_activity, material=wool, solution_part=part)