Exemple #1
0
    def test_node_counts(self):
        """
        Add 2 scenarios with varying #'s of nodes and
        ensure that they have the correct counts
        """
        from next.model.models import Scenario, Phase, get_cumulative_nodes
        scen1 = Scenario(u'scenario1')
        scen2 = Scenario(u'scenario2')
        phase1 = Phase(scen1)
        phase2 = Phase(scen2)

        self.session.add_all([scen1, scen2, phase1, phase2])
        scen1_nodes = nodes_along_latitude(10, phase1, self.session)
        self.session.add_all(scen1_nodes)
        scen2_nodes = nodes_along_latitude(20, phase2, self.session)
        self.session.add_all(scen2_nodes)

        self.assertEqual(10, get_cumulative_nodes(scen1.id, phase1.id).count()) 
        self.assertEqual(20, get_cumulative_nodes(scen2.id, phase2.id).count()) 
Exemple #2
0
def show_cumulative_phase_nodes(request):
    """ 
    Returns nodes as geojson
    type parameter used as a filter
    If type=='demand', then add nearest-neighbor distance to output
    """

    session = DBSession()
    phase = get_object_or_404(Phase, request, ('phase_id', 'id'))
    nodes = []
    if (request.GET.has_key("type")):
        request_node_type = request.GET["type"]
        if(request_node_type == "demand"):
            return show_cumulative_phase_demand_json(phase)
        else: 
            nodes = get_cumulative_nodes(phase.scenario_id, phase.id, node_type=request_node_type)
    else:
        nodes = get_cumulative_nodes(phase.scenario_id, phase.id)

    return to_geojson_feature_collection(nodes)