Beispiel #1
0
def make_css_from_statements(lines, compressed=True, empty_selectors=True, indent='    ', target=None):
    if compressed:
        indent = ''
        try:
            from cssmin import cssmin
        except ImportError:
            def cssmin(css, wrap=None):
                pass
    _media, _indent = [], ''
    for media, selectors, declarations in last(lines, ([], [], [])):
        if media != _media:
            if _media:
                target.send('}')
                yield '}'
                _indent = ''
            if media:
                yield (','.join(media) + '{') if compressed else (', '.join(media) + ' {')
                _indent = indent
        if selectors == ['@import']:
            for _, path in declarations:
                with open(path) as f:
                    content = f.read()
                    if content:
                        yield cssmin(content) if compressed else content
        elif empty_selectors or declarations:
            declarations = [_indent + indent + k + (':' if compressed else ': ') + str(v) + ';' for k, v in declarations]
            if selectors:
                if compressed:
                    line = ','.join(selectors) + '{' + ''.join(declarations) + '}'
                else:
                    line = _indent + (',\n' + _indent).join(selectors)
                    line += ' {\n' + '\n'.join(declarations) + '\n' + _indent + '}'
                if line:
                    yield line
        _media = media
Beispiel #2
0
def make_statements_list(lines):
    selectors, declarations = [], []
    for name, sel, _sel in last(lines, (None, True, False)):
        if sel:
            if not _sel and selectors:
                yield selectors, declarations
                selectors, declarations = [], []
            selectors.append(name)
        elif name != 'pass':
            declarations.append(name)
Beispiel #3
0
def site_detail(site_id):
    site = Site.get_by_key_name(site_id)
    if site is None:
        return Response(status = 404)

    obs = ObservationTimestep.find_latest_by_site(site = site, limit = 24)
    forecasts = []
    if len(obs) > 0:
        first_obs = first(obs)
        last_obs = last(obs)

        forecasts = ForecastTimestep.find_by_site_between_dates( site = site,
                                                                 from_dt = last_obs.observation_datetime,
                                                                 to_dt = first_obs.observation_datetime)
    return Response(json.dumps({
       'site': site.to_dict(),
       'observations': map(lambda o: o.to_dict(excluding = ['site']), obs),
       'forecasts': map(lambda f: f.to_dict(excluding = ['site']), forecasts)
    }), content_type = "application/json")
def find_directions(link, probes, get_distance=get_distance):
    by_sample_id = group_by('sampleID', probes)

    result = {}
    for (sample_id, probes) in by_sample_id:
        sorted_by_datetime = sorted(
            probes, key=lambda p: datetime_parser.parse(p.dateTime))

        if len(sorted_by_datetime) > 1:
            distance_from_first = find_distance_from_ref(
                link, first(sorted_by_datetime))
            distance_from_last = find_distance_from_ref(
                link, last(sorted_by_datetime))
            result[
                sample_id] = 'F' if distance_from_first < distance_from_last else 'T'
        else:
            result[sample_id] = '?'

    return result
Beispiel #5
0
 def make_move_goals(self):
     order = last(self.pubsub.move_orders)
     if order is None:
         return
     player = self.get_player_entity()
     self.registry.assign(player, Goal, GoalType.MOVE, position=order)