def render_results(doc_id): """ Render results page """ doc = mongo.find_document('connectthedots', doc_id) results = doc.get('results') if doc.get('source') != 'sample': remaining_days = mongo.get_remaining_days('connectthedots', doc_id) else: remaining_days = None first_mismatch = None # get first centrality/degree mismatch degree_index = 0 centrality_index = 0 table_by_degree = sorted(results['table'], key=operator.itemgetter('degree'), reverse=True) table_by_centrality = results['table'] for i, row in enumerate(table_by_degree): if row['id'] != table_by_centrality[i]['id']: first_mismatch = row['id'] degree_index = i break if first_mismatch is not None: for i, row in enumerate( table_by_centrality[degree_index + 1:]): # start from where we left off if row['id'] == first_mismatch: centrality_index = i + degree_index + 1 break what_next = { 'mismatch_id': first_mismatch, 'mismatch_degree': ordinal(degree_index + 1), 'mismatch_centrality': ordinal(centrality_index + 1), 'lowest_degree': table_by_degree[-1]['id'] } biography = results['biography'] if 'biography' in results else None return render_template('connectthedots/results.html', results=results, whatnext=what_next, tool_name='connectthedots', source=doc['source'], has_multiple_sheets=results['has_multiple_sheets'], remaining_days=remaining_days, biography=biography)
def render_results(doc_id): """ Render results page """ doc = mongo.find_document('connectthedots', doc_id) results = doc.get('results') if doc.get('source') != 'sample': remaining_days = mongo.get_remaining_days('connectthedots', doc_id) else: remaining_days = None first_mismatch = None # get first centrality/degree mismatch degree_index = 0 centrality_index = 0 table_by_degree = sorted(results['table'], key=operator.itemgetter('degree'), reverse=True) table_by_centrality = results['table'] for i, row in enumerate(table_by_degree): if row['id'] != table_by_centrality[i]['id']: first_mismatch = row['id'] degree_index = i break if first_mismatch is not None: for i, row in enumerate(table_by_centrality[degree_index + 1:]): # start from where we left off if row['id'] == first_mismatch: centrality_index = i + degree_index + 1 break whatnext = {} whatnext['mismatch_id'] = first_mismatch whatnext['mismatch_degree'] = ordinal(degree_index + 1) whatnext['mismatch_centrality'] = ordinal(centrality_index + 1) whatnext['lowest_degree'] = table_by_degree[-1]['id'] return render_template('connectthedots/results.html', results=results, whatnext=whatnext, tool_name='connectthedots', source=doc['source'], has_multiple_sheets=results['has_multiple_sheets'], remaining_days=remaining_days)
def test_ordinal(self): for test, expect in ( (1, u'1st'), (3, u'3rd'), (11, u'11th'), (101, u'101st'), (104, u'104th'), (113, u'113th'), (123, u'123rd'), ): result = number.ordinal(test) assert result == expect, '%r <> %r' % (result, expect)
def time_tick(): # Game Calendar - May be more useful later? qcalen = [ "Jannus", "Quintest", "Everborn", "Sprynthane", "Tavyris", "Midsummers", "Entmordaughn", "Autumnus", "Harvestone", "Fallowfield", "Winterholm" ] qweekd = [ "Sunstone", "Mondred", "Tuendala", "Wednyght", "Threasdon", "Frindaal", "Satterdawn" ] qclock = [ "12:00am", "1:00am", "2:00am", "3:00am", "4:00am", "5:00am", "6:00am", "7:00am", "8:00am", "9:00am", "10:00am", "11:00am", "12:00pm", "1:00pm", "2:00pm", "3:00pm", "4:00pm", "5:00pm", "6:00pm", "7:00pm", "8:00pm", "9:00pm", "10:00pm", "11:00pm" ] year = 1670 mtod = 0 mnth = 5 days = 0 hour = 7 hour = hour + hero.gametime while hour >= len(qclock): hour = hour - len(qclock) days = days + 1 mtod = mtod + 1 if days >= len(qweekd): days = days - len(qweekd) if mtod >= 31: mtod = 0 mnth = mnth + 1 if mnth >= len(qcalen): mnth = mnth - len(qcalen) year = year + 1 global gamedate gamedate = (qweekd[days] + ", " + qcalen[mnth] + " " + ordinal(str(mtod + 1)) + ", " + str(year) + ", " + qclock[hour]) return gamedate
def to_human(self, value): return ordinal(int(value))
def ordinal(value): '''Wrapper for :func:`natural.number.ordinal`''' return number.ordinal(value)