Esempio n. 1
0
def open_scenario(request, target, wrap_target=True):
    if wrap_target:
        target = workspace_path(target)
    print("Copying ", target, "to", db_path(), ". This could take several minutes...")
    close_old_connections()
    shutil.copy(target, db_path(name='scenario_db'))
    scenario_filename(os.path.basename(target))
    print('Sessions overwritten with ', target)
    update_db_version()
    unsaved_changes(False)  # File is now in sync
    SmSession.objects.all().update(iteration_text = '', simulation_has_started=outputs_exist())  # This is also reset from delete_all_outputs
    # else:
    #     print('File does not exist')
    return redirect('/setup/Scenario/1/')
Esempio n. 2
0
def results_context(request):
    context = {}
    
    if not request.is_ajax() and ('results/' in request.path or 'setup/' in request.path):  # results specific context
        session = SmSession.objects.get()
        context.update({'simulation_has_started': session.simulation_has_started,
                        'outputs_exist': outputs_exist(),
                        'results_progress': iteration_progress() * 100,})

        try:
            version = ResultsVersion.objects.all().first().__str__()  # singleton doesn't always work on this model (legacy)
        except:
            version = "No version available"
        context.update({
                        'is_simulation_running': is_simulation_running(),
                        'is_simulation_stopped': is_simulation_stopped(),
                        'iterations_completed': iterations_complete(),
                        'version_number': version
    
        })
        context.update(excluded_headers())

    return context
Esempio n. 3
0
def basic_context(request):
    context = {'request': request}
    if request.path and request.path != '/' and '/LoadingScreen/' not in request.path:  # #635 this needs to run even in AJAX
        context['outputs_exist'] = outputs_exist()  # I don't want this triggering on LoadingScreen

    if not request.is_ajax() and 'setup/' in request.path:  # inputs specific context not filled from ajax requests
        pt_count = ProductionType.objects.count()

        context.update({
               'Scenario': Scenario.objects.count(),
               'OutputSetting': OutputSettings.objects.count(),
               'Population': Unit.objects.count(),
               'ProductionTypes': ProductionType.objects.all().annotate(unit_count=Count('unit')).values('name', 'unit_count', 'description'),
               'ProductionGroups': ProductionGroup.objects.all(),
               'Farms': Unit.objects.count(),
               'Disease': Disease.objects.all().exclude(name='').count(),
               'Progressions': DiseaseProgression.objects.count() and pt_count,
               'ProgressionAssignment': pt_count and DiseaseProgressionAssignment.objects.filter(progression__isnull=False).count() == pt_count,
               'DirectSpreads': DirectSpread.objects.count(),
               'AssignSpreads': pt_count and
                                DiseaseSpreadAssignment.objects.filter(  #completely empty assignments
                                    direct_contact_spread__isnull=True,
                                    indirect_contact_spread__isnull=True,
                                    airborne_spread__isnull=True
                                ).count() < pt_count ** 2,  # all possible assignments == pt_count^2
               'ControlMasterPlan': ControlMasterPlan.objects.count(),
               'VaccinationTrigger': any([m.objects.count() for m in 
                                          [DiseaseDetection,RateOfNewDetections,DisseminationRate,TimeFromFirstDetection,DestructionWaitTime,SpreadBetweenGroups]]),
               'Protocols': ControlProtocol.objects.count(),
               'ProtocolAssignments': ProtocolAssignment.objects.count(),
               'Zones': Zone.objects.count(),
               'ZoneEffects': ZoneEffect.objects.count(),
               'ZoneEffectAssignments': ZoneEffectAssignment.objects.filter(effect__isnull=False).count() >= Zone.objects.count() and Zone.objects.count(),
               'ProbabilityFunctions': ProbabilityFunction.objects.count(),
               'RelationalFunctions': RelationalFunction.objects.count(),
               'controls_enabled': ControlMasterPlan.objects.filter(disable_all_controls=True).count() == 0,
               })

        validation_models = {'Scenario': 'Scenario/1/', 
                             'OutputSetting': 'OutputSetting/1/', 
                             'Population': 'Populations/', 
                             'ProductionTypes': 'ProductionType/', 
                             'Farms': 'Populations/', 
                             'Disease': 'Disease/1/', 
                             'Progressions': 'AssignProgressions/',
                             'DirectSpreads': 'DirectSpreads/', 
                             'AssignSpreads': 'AssignSpreads/', 
                             'ControlMasterPlan': 'ControlMasterPlan/1/', 
                             'Protocols': 'ControlProtocol/', 
                             'ProtocolAssignments': 'AssignProtocols/', 
                             'Zones': 'Zone/', 
                             'ZoneEffects': 'ZoneEffect/',
                             'ZoneEffectAssignments': 'AssignZoneEffects/'}
        context['missing_values'] = {singular(name): validation_models[name] for name in validation_models if not context[name]}
        context['Simulation_ready'] = not len(context['missing_values'])
        disease = Disease.objects.get()
        context['javascript_variables'] = {'use_within_unit_prevalence':      js(disease.use_within_unit_prevalence),
                                           'use_airborne_exponential_decay':  js(disease.use_airborne_exponential_decay),
                                           'include_direct_contact_spread':   js(disease.include_direct_contact_spread),
                                           'include_indirect_contact_spread': js(disease.include_indirect_contact_spread),
                                           'include_airborne_spread':         js(disease.include_airborne_spread),
                                           'outputs_exist':                   js(outputs_exist()),
                                           'controls_enabled':                js(context['controls_enabled']),
                                           }
        
    return context