def link_vertices_with_namedreaches():
    for named_reach in models.NamedReach.objects.all():
        rs = utils.namedreach2riversegments(named_reach)
        vertices = models.Vertex.objects.filter(
            vertexvalue__riversegment__in=rs).distinct()
        for vertex in vertices:
            vertex.named_reaches.add(named_reach)
            vertex.save()
    def handle(self, *args, **options):
        if len(args) == 0:
            print "Pass excel files as arguments."
            sys.exit(1)

        map(self.parse, args)
        #Link Vertexes with the NamedReaches
        for named_reach in models.NamedReach.objects.all():
            rs = utils.namedreach2riversegments(named_reach)
            vertexes = models.Vertex.objects.filter(
                vertexvalue__riversegment__in=rs).distinct()
            for vertex in vertexes:
                vertex.named_reaches.add(named_reach)
                vertex.save()
Exemplo n.º 3
0
def _water_levels(request):
    selected_river = _selected_river(request)
    selected_measures = _selected_measures(request)
    selected_vertex = _selected_vertex(request)
    cache_key = (str(selected_river) + str(selected_vertex.id) +
                 ''.join(selected_measures))
    cache_key = md5(cache_key).hexdigest()
    water_levels = cache.get(cache_key)
    if not water_levels:
        logger.info("Cache miss for _water_levels")

        measures = models.Measure.objects.filter(
            short_name__in=selected_measures)
        riversegments = namedreach2riversegments(selected_river)
        segment_levels = [_segment_level(segment, measures, selected_vertex)
                        for segment in riversegments]
        water_levels = [segment for segment in segment_levels if segment]
        cache.set(cache_key, water_levels, 5 * 60)
    return water_levels