Ejemplo n.º 1
0
 def test_ranges(self):
     ranges = periodRanges(VOCAB)
     items = sorted(ranges.items())
     self.failUnlessEqual(
         items,
         [("hellenistic-republican", (-330.0, -30.0)), ("late-antique", (300.0, 640.0)), ("roman", (-30.0, 300.0))],
     )
Ejemplo n.º 2
0
def dump_catalog(context, portal_type, cschema, **extras):
    schema = cschema.copy()
    
    vocabs = getToolByName(context, 'portal_vocabularies')
    tp_vocab = vocabs.getVocabularyByName('time-periods').getTarget()
    tp_ranges = periodRanges(tp_vocab)

    include_features = False
    kwextras = extras.copy()
    if 'include_features' in kwextras:
        include_features = True
        del kwextras['include_features']
    catalog = getToolByName(context, 'portal_catalog')
    if 'collection_path' in extras:
        collection = catalog(
            path={'query': extras['collection_path'], 'depth': 0}
            )[0].getObject()
        targets = collection.queryCatalog()
        results = []
        for target in targets:
            results += catalog(
                path=target.getPath(), portal_type=portal_type, **kwextras)
    else:
        query = {'portal_type': portal_type}
        if not include_features:
            query.update(
                path={'query': '/plone/places', 'depth': 2},
                review_state='published' )
        query.update(kwextras)
        results = catalog(query)
    writer = UnicodeWriter(sys.stdout)
    keys = sorted(schema.keys())
    writer.writerow(keys)
    if include_features:
        schema['pid'] = getFeaturePID
    for b in results:

        # representative point
        try:
            lon, lat = map(float, b.reprPt[0])
            precision = b.reprPt[1]
            schema['reprLat'] = lambda a, b: str(lat)
            schema['reprLong'] = lambda a, b: str(lon)
            schema['reprLatLong'] = lambda a, b: "%f,%f" % (lat, lon)
        except:
            log.warn("Unlocated: %s" % b.getPath())

        # dates
        years = []
        for tp in getattr(b, 'getTimePeriods', []):
            if tp:
                years.extend(list(tp_ranges[tp]))
        if len(years) >= 2:
            dmin, dmax = min(years), max(years)
            schema['minDate'] = lambda a, b: str(dmin)
            schema['maxDate'] = lambda a, b: str(dmax)
            schema['timePeriodsRange'] = lambda a, b: "%.1f,%.1f" % (dmin, dmax)

        writer.writerow([schema[k](b, catalog) or "" for k in keys])
Ejemplo n.º 3
0
    def test_range(self):

        class MockTemporalContent(Temporal.Temporal):
            def getAttestations(self):
                return [
                    {'timePeriod': 'hellenistic-republican', 'confidence': 'confident'},
                    {'timePeriod': 'roman', 'confidence': 'confident'}]

        mock = MockTemporalContent()
        ranges = periodRanges(VOCAB)
        self.failUnlessEqual(mock.temporalRange(ranges), (-330.0, 300.0))
Ejemplo n.º 4
0
def getDates2(rec, catalog):
    """Nominal temporal range, not accounting for level of confidence"""
    vocab = getToolByName(
        catalog, 'portal_vocabularies'
        ).getVocabularyByName('time-periods').getTarget()
    ranges = periodRanges(vocab)
    years = []
    for tp in getattr(rec, 'getTimePeriods', []):
        if tp:
            years.extend(list(ranges[tp]))
    if len(years) >= 2:
        return "%.1f,%.1f" % (min(years), max(years))
    else:
        return None
Ejemplo n.º 5
0
 def temporalRange(self, period_vocab=None):
     """Nominal temporal range, not accounting for level of confidence"""
     vocab = period_vocab or self.period_vocab()
     ranges = periodRanges(vocab)
     years = []
     check = self.getAttestations()
     for a in self.getAttestations():
         tp = a['timePeriod']
         if tp:
             years.extend(list(ranges[a['timePeriod']]))
     if len(years) >= 2:
         return min(years), max(years)
     else:
         return None
Ejemplo n.º 6
0
 def timeSpan(self):
     catalog = self.context.aq_parent
     vocab = get_vocabulary('time_periods')
     ranges = periodRanges(vocab)
     years = []
     tp = getattr(self.context, 'getTimePeriods', [])
     if callable(tp):
         values = tp()
     else:
         values = tp
     for val in values:
         if val and val in ranges:
             years.extend(list(ranges[val]))
     if len(years) >= 2:
         return {'start': int(min(years)), 'end': int(max(years))}
     else:
         return None
Ejemplo n.º 7
0
    def temporalRange(self):
        # @@@ move to util function
        request = getRequest()
        if request is not None and hasattr(request, '_period_ranges'):
            period_ranges = request._period_ranges
        else:
            tp_vocab = get_vocabulary('time_periods')
            period_ranges = periodRanges(tp_vocab)
            if request is not None:
                request._period_ranges = period_ranges

        timePeriods = self.brain.getTimePeriods
        years = []
        for period in timePeriods:
            years.extend(list(period_ranges[period]))
        if len(years) >= 2:
            return min(years), max(years)
        else:
            return None
Ejemplo n.º 8
0
 def timeSpan(self):
     catalog = self.context.aq_parent
     vocab = getToolByName(
         catalog, 'portal_vocabularies'
         ).getVocabularyByName('time-periods').getTarget()
     ranges = periodRanges(vocab)
     years = []
     tp = getattr(self.context, 'getTimePeriods', [])
     if callable(tp):
         values = tp()
     else:
         values = tp
     for val in values:
         if val:
             years.extend(list(ranges[val]))
     if len(years) >= 2:
         return {'start': int(min(years)), 'end': int(max(years))}
     else:
         return None
Ejemplo n.º 9
0
    def temporalRange(self, period_ranges=None):
        """Nominal temporal range, not accounting for level of confidence"""
        # cache period ranges on request
        if period_ranges is None:
            request = getRequest()
            if request is not None and hasattr(request, '_period_ranges'):
                period_ranges = request._period_ranges
            else:
                vocab = get_vocabulary('time_periods')
                period_ranges = periodRanges(vocab)
                if request is not None:
                    request._period_ranges = period_ranges

        years = []
        for a in self.getAttestations():
            tp = a['timePeriod']
            if tp:
                years.extend(list(period_ranges[a['timePeriod']]))
        if len(years) >= 2:
            return min(years), max(years)
        else:
            return None
Ejemplo n.º 10
0
 def periodRanges(self):
     vocab = getToolByName(
         self.context.getObject(), 'portal_vocabularies'
         ).getVocabularyByName('time-periods').getTarget()
     return periodRanges(vocab)
Ejemplo n.º 11
0
 def periodRanges(self):
     vocab = get_vocabulary('time_periods')
     return periodRanges(vocab)
Ejemplo n.º 12
0
 def test_overlap(self):
     p = MockTemporalContent([{'timePeriod': 'roman'}])
     q = MockTemporalContent([{'timePeriod': 'roman'}])
     ranges = periodRanges(VOCAB)
     self.failUnless(temporal_overlap(p, q, ranges))
Ejemplo n.º 13
0
 def test_nonoverlap(self):
     p = MockTemporalContent([{'timePeriod': 'hellenistic-republican'}])
     q = MockTemporalContent([{'timePeriod': 'roman'}])
     ranges = periodRanges(VOCAB)
     self.failIf(temporal_overlap(p, q, ranges))