Esempio n. 1
0
    def get_legends(self):
        def img(spec):
            return HTML.img(src=svg.data_url(svg.icon(spec)),
                            height='20',
                            width='20',
                            style='margin-left: 0.5em;')

        def desc(text):
            return HTML.span(text,
                             style='margin-left: 0.5em; margin-right: 0.5em;')

        values = [desc('Most extensive description is a ...')]
        for sdt in get_parameter('med').domain:
            icon = self.de_to_icon['med'][sdt.id.split('-')[1]]
            values.append(
                HTML.label(
                    HTML.input(
                        type='checkbox',
                        checked='checked',
                        id='marker-toggle-sdt-' + str(sdt.number),
                        onclick='GLOTTOLOG3.LangdocStatus.toggleMarkers()'),
                    img(icon.shape + 'ffffff' if self.focus == 'ed' else 'c' +
                        icon.color), desc(sdt.name)))
        values.append(desc('Language is ...'))
        for ed in get_parameter('aes').domain:
            icon = self.de_to_icon['aes'][ed.id.split('-')[1]]
            values.append((HTML.label(
                HTML.input(type='checkbox',
                           checked='checked',
                           id='marker-toggle-ed-' + str(ed.number),
                           onclick='GLOTTOLOG3.LangdocStatus.toggleMarkers()'),
                img('c' + icon.color if self.focus == 'ed' else icon.shape +
                    'ffffff'), desc(ed.name.lower()))))
        yield Legend(self, 'values', values, label='Legend')
Esempio n. 2
0
 def __init__(self, obj):
     GeoJson.__init__(self, obj)
     aes = get_parameter('aes')
     med = get_parameter('med')
     self.ldstatus = ldstatus(aes.pk)
     self.med_map = {
         de.id.split('-')[1]: (Icon.from_spec(de.jsondata['icon']), de)
         for de in med.domain
     }
     self.med_map[None] = self.med_map['wordlist_or_less']
     self.aes_map = {
         de.pk: (Icon.from_spec(de.jsondata['icon']), de)
         for de in aes.domain
     }
Esempio n. 3
0
def browser(req):
    """
    The main GlottoScope view, with selection controls, map and tally table.
    """
    ms = MultiSelect(req,
                     'families',
                     'msfamily',
                     collection=family_query(req),
                     selected=_get_families(req))

    focus = req.params.get('focus', 'ed')

    im = get_icon_map()
    if focus == 'sdt':
        colors, shapes = im['med'], im['aes']
    else:
        shapes, colors = im['med'], im['aes']

    icon_map = {}
    for shape in [o.shape for o in shapes.values()]:
        for color in [o.color for o in colors.values()] + ['ffffff']:
            spec = shape + color
            icon_map[spec] = req.static_url('clld:web/static/icons/%s.png' %
                                            spec)

    countries = OrderedDict()
    for c in req.params.getall('country'):
        countries[c] = DBSession.query(common.DomainElement).join(common.Parameter)\
            .filter(common.Parameter.id == 'country')\
            .filter(common.DomainElement.name == c)\
            .one().description

    return {
        'families':
        ms,
        'macroareas':
        get_parameter('macroarea'),
        'countries':
        countries,
        'map':
        DescStatsMap(language_query(req), req, icon_map, focus, im),
        'icon_map':
        icon_map,
        'focus':
        focus,
        'doctypes': [(de, Icon.from_spec(de.jsondata['icon']))
                     for de in get_parameter('med').domain],
        'endangerments': [(de, Icon.from_spec(de.jsondata['icon']))
                          for de in get_parameter('aes').domain],
    }
Esempio n. 4
0
def langdoccomplexquery(request):
    res = {
        'dt': None,
        'doctypes': DBSession.query(Doctype).order_by(Doctype.id),
        'macroareas': get_parameter('macroarea').domain,
        'ms': {}
    }

    for name, cls, kw in [
        ('languoids', LanguoidsMultiSelect,
         dict(url=request.route_url('glottolog.childnodes'))),
        ('macroareas', MultiSelect, dict(collection=res['macroareas'])),
        ('doctypes', MultiSelect, dict(collection=res['doctypes'])),
    ]:
        res['ms'][name] = cls(request, name, 'ms' + name, **kw)

    res['params'], reqparams = get_params(request.params, **res)
    res['refs'] = getRefs(res['params'])

    if res['refs']:
        res['dt'] = Refs(request, Source, cq=1, **reqparams)

    fmt = request.params.get('format')
    if fmt:
        db = bibtex.Database([ref.bibtex() for ref in res['refs']])
        for name, adapter in request.registry.getAdapters([db],
                                                          IRepresentation):
            if name == fmt:
                return adapter.render_to_response(db, request)
        return HTTPNotAcceptable()

    return res
Esempio n. 5
0
def intro(req):
    def count(ppk):
        return DBSession.query(common.DomainElement.pk, func.count(common.Value.pk))\
            .join(common.Value)\
            .join(common.ValueSet)\
            .join(common.Language)\
            .filter(Languoid.category.in_(CATEGORIES))\
            .filter(common.DomainElement.parameter_pk == ppk)\
            .group_by(common.DomainElement.pk)

    med = get_parameter('med')
    aes = get_parameter('aes')
    return {
        'aes': aes,
        'med': med,
        'ref': get_source(aes.jsondata['reference_id']),
        'macroareas': get_parameter('macroarea').domain,
        'families': family_query(),
        'med_type_count': {pk: c
                           for pk, c in count(med.pk)},
        'aes_status_count': {pk: c
                             for pk, c in count(aes.pk)},
    }
Esempio n. 6
0
def get_icon_map():
    res = defaultdict(dict)
    for pid in ['aes', 'med']:
        for de in get_parameter(pid).domain:
            res[pid][de.id.split('-')[1]] = Icon.from_spec(de.jsondata['icon'])
    return res
Esempio n. 7
0
def languages(req):
    """
    Called when cells in the tally table are clicked to load the corresponding languages.

    :param req:
    :return: list of (language, med) pairs with matching endangerment and doctype.
    """
    macroarea = req.params.get('macroarea')
    family = _get_families(req)
    year = req.params.get('year')

    demap = defaultdict(dict)
    for pid in ['aes', 'med']:
        for de in get_parameter(pid).domain:
            demap[pid][de.number] = de

    aes, aeslpks, med, medlpks = None, [], None, []

    label = 'Languages'
    if int(req.matchdict['ed']) in demap['aes']:
        aes = demap['aes'][int(req.matchdict['ed'])]
        label = HTML.em(aes.name) + ' languages'
        aeslpks = {
            v.valueset.language_pk for v in DBSession.query(common.Value)\
                .filter(common.Value.domainelement_pk == aes.pk)\
                .options(joinedload(common.Value.valueset))}

    if family:
        label = label + ' of the %s families' % ', '.join(f.name
                                                          for f in family)

    if macroarea:
        label = label + ' from ' + macroarea

    if int(req.matchdict['sdt']) in demap['med']:
        med = demap['med'][int(req.matchdict['sdt'])]
        medlpks = {
            v.valueset.language_pk for v in DBSession.query(common.Value) \
                .filter(common.Value.domainelement_pk == med.pk) \
                .options(joinedload(common.Value.valueset))}

        label = label + ' whose most extensive description'

        if year:
            year = int(year)
            label = label + ' in %s' % year

        label = label + ' is a ' + med.name

    stats = ldstatus(get_parameter('aes').pk)
    langs = []
    for lang in language_query(req):
        if aes and lang.pk not in aeslpks:
            continue
        if not year and (med and lang.pk not in medlpks):
            continue

        aespk, med_, sources, _ = stats.get(lang.id, (None, None, [], None))
        gmed = None
        if year:
            drop = True
            for s in sources:
                s = src2dict(
                    s, {v.id.split('-')[1]: v
                        for v in demap['med'].values()})
                if s['year'] <= int(year):
                    gmed = s
                    if med and gmed['med_type'] == med.id.split('-')[1]:
                        drop = False
                    break
            if drop and med:
                continue
        else:
            gmed = med_
        langs.append((lang, gmed))

    return {
        'languages': sorted(langs, key=lambda l: l[0].name),
        'label': label
    }
Esempio n. 8
0
def countries_as_json():
    return json.dumps([
        '%s (%s)' % (c.description, c.name)
        for c in get_parameter('country').domain
    ])