本文整理汇总了Python中helpers.event_details_manipulator.EventDetailsManipulator类的典型用法代码示例。如果您正苦于以下问题:Python EventDetailsManipulator类的具体用法?Python EventDetailsManipulator怎么用?Python EventDetailsManipulator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventDetailsManipulator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self, event_key):
event = Event.get_by_id(event_key)
if not event:
self.abort(404)
if not event.remap_teams:
return
event.prepAwardsMatchesTeams()
# Remap matches
EventHelper.remapteams_matches(event.matches, event.remap_teams)
MatchManipulator.createOrUpdate(event.matches)
# Remap alliance selections
if event.alliance_selections:
EventHelper.remapteams_alliances(event.alliance_selections, event.remap_teams)
# Remap rankings
if event.rankings:
EventHelper.remapteams_rankings(event.rankings, event.remap_teams)
if event.details and event.details.rankings2:
EventHelper.remapteams_rankings2(event.details.rankings2, event.remap_teams)
EventDetailsManipulator.createOrUpdate(event.details)
# Remap awards
EventHelper.remapteams_awards(event.awards, event.remap_teams)
AwardManipulator.createOrUpdate(event.awards, auto_union=False)
示例2: get
def get(self, event_key):
event = Event.get_by_id(event_key)
matchstats_dict = MatchstatsHelper.calculate_matchstats(event.matches, event.year)
if any([v != {} for v in matchstats_dict.values()]):
pass
else:
logging.warn("Matchstat calculation for {} failed!".format(event_key))
matchstats_dict = None
predictions_dict = None
if event.year == 2016:
organized_matches = MatchHelper.organizeMatches(event.matches)
match_predictions, match_prediction_stats = PredictionHelper.get_match_predictions(organized_matches['qm'])
ranking_predictions, ranking_prediction_stats = PredictionHelper.get_ranking_predictions(organized_matches['qm'], match_predictions)
predictions_dict = {
'match_predictions': match_predictions,
'match_prediction_stats': match_prediction_stats,
'ranking_predictions': ranking_predictions,
'ranking_prediction_stats': ranking_prediction_stats
}
event_details = EventDetails(
id=event_key,
matchstats=matchstats_dict,
predictions=predictions_dict
)
EventDetailsManipulator.createOrUpdate(event_details)
template_values = {
'matchstats_dict': matchstats_dict,
}
path = os.path.join(os.path.dirname(__file__), '../templates/math/event_matchstats_do.html')
self.response.out.write(template.render(path, template_values))
示例3: post
def post(self, event_key_id):
self._require_admin()
event = Event.get_by_id(event_key_id)
if not event:
self.redirect("/admin/event/" + event.key_name)
return
event_details = event.details
if not event_details or not event_details.alliance_selections:
# No alliance data to modify
self.redirect("/admin/event/" + event.key_name)
return
team_in = "frc{}".format(self.request.get("backup_in"))
team_out = "frc{}".format(self.request.get("backup_out"))
# Make sure both teams are attending the event
et_in = EventTeam.get_by_id("{}_{}".format(event.key_name, team_in))
et_out = EventTeam.get_by_id("{}_{}".format(event.key_name, team_out))
if not et_in and et_out:
# Bad teams supplied
self.redirect("/admin/event/" + event.key_name)
return
for alliance in event_details.alliance_selections:
if team_out in alliance.get('picks', []):
alliance['backup'] = {}
alliance['backup']['in'] = team_in
alliance['backup']['out'] = team_out
EventDetailsManipulator.createOrUpdate(event_details)
break
self.redirect("/admin/event/" + event.key_name)
return
示例4: create_event_details
def create_event_details(event_key):
event = Event.get_by_id(event_key)
if event.alliance_selections or event.district_points or event.matchstats or event.rankings:
event_details = EventDetails(
id=event_key,
alliance_selections=event.alliance_selections,
district_points=event.district_points,
matchstats=event.matchstats,
rankings=event.rankings)
EventDetailsManipulator.createOrUpdate(event_details)
示例5: _process_request
def _process_request(self, request, event_key):
rankings = JSONRankingsParser.parse(request.body)
event = Event.get_by_id(event_key)
event_details = EventDetails(
id=event_key,
rankings=rankings
)
EventDetailsManipulator.createOrUpdate(event_details)
self.response.out.write(json.dumps({'Success': "Rankings successfully updated"}))
示例6: _process_request
def _process_request(self, request, event_key):
rankings = JSONRankingsParser.parse(request.body)
event_details = EventDetails(
id=event_key,
rankings=rankings
)
if event_details.year >= 2017: # TODO: Temporary fix. Should directly parse request into rankings2
event_details.rankings2 = RankingsHelper.convert_rankings(event_details)
EventDetailsManipulator.createOrUpdate(event_details)
self.response.out.write(json.dumps({'Success': "Rankings successfully updated"}))
示例7: _process_request
def _process_request(self, request, event_key):
alliance_selections = JSONAllianceSelectionsParser.parse(request.body)
event_details = EventDetails(
id=event_key,
alliance_selections=alliance_selections
)
if self.event.remap_teams:
EventHelper.remapteams_alliances(event_details.alliance_selections, self.event.remap_teams)
EventDetailsManipulator.createOrUpdate(event_details)
self.response.out.write(json.dumps({'Success': "Alliance selections successfully updated"}))
示例8: post
def post(self, event_key):
self._require_admin()
# Note, we don't actually use event_key.
start_date = None
if self.request.get("start_date"):
start_date = datetime.strptime(self.request.get("start_date"), "%Y-%m-%d")
end_date = None
if self.request.get("end_date"):
end_date = datetime.strptime(self.request.get("end_date"), "%Y-%m-%d")
district_key = self.request.get("event_district_key", None)
event = Event(
id=str(self.request.get("year")) + str.lower(str(self.request.get("event_short"))),
end_date=end_date,
event_short=self.request.get("event_short"),
event_type_enum=EventHelper.parseEventType(self.request.get("event_type_str")),
district_key=ndb.Key(District, self.request.get("event_district_key")) if district_key and district_key != 'None' else None,
venue=self.request.get("venue"),
venue_address=self.request.get("venue_address"),
city=self.request.get("city"),
state_prov=self.request.get("state_prov"),
postalcode=self.request.get("postalcode"),
country=self.request.get("country"),
name=self.request.get("name"),
short_name=self.request.get("short_name"),
start_date=start_date,
website=self.request.get("website"),
year=int(self.request.get("year")),
official={"true": True, "false": False}.get(self.request.get("official").lower()),
facebook_eid=self.request.get("facebook_eid"),
custom_hashtag=self.request.get("custom_hashtag"),
webcast_json=self.request.get("webcast_json"),
playoff_type=int(self.request.get("playoff_type")),
)
event = EventManipulator.createOrUpdate(event)
if self.request.get("alliance_selections_json") or self.request.get("rankings_json"):
event_details = EventDetails(
id=event_key,
alliance_selections=json.loads(self.request.get("alliance_selections_json")),
rankings=json.loads(self.request.get("rankings_json"))
)
EventDetailsManipulator.createOrUpdate(event_details)
MemcacheWebcastFlusher.flushEvent(event.key_name)
self.redirect("/admin/event/" + event.key_name)
示例9: get
def get(self, year):
self._require_admin()
event_keys = Event.query(Event.year==int(year)).fetch(keys_only=True)
event_details = ndb.get_multi([ndb.Key(EventDetails, key.id()) for key in event_keys])
updated = []
for event_detail in event_details:
if event_detail:
logging.info(event_detail.key.id())
event_detail.rankings2 = RankingsHelper.convert_rankings(event_detail)
updated.append(event_detail)
EventDetailsManipulator.createOrUpdate(updated)
self.response.out.write("DONE")
示例10: _update_rankings
def _update_rankings(self):
"""
Generates and saves fake rankings
"""
event = Event.get_by_id('2016nytr')
team_wins = defaultdict(int)
team_losses = defaultdict(int)
team_ties = defaultdict(int)
teams = set()
for match in event.matches:
if match.comp_level == 'qm':
for alliance in ['red', 'blue']:
for team in match.alliances[alliance]['teams']:
teams.add(team)
if match.has_been_played:
if alliance == match.winning_alliance:
team_wins[team] += 1
elif match.winning_alliance == '':
team_ties[team] += 1
else:
team_losses[team] += 1
rankings = []
for team in sorted(teams):
wins = team_wins[team]
losses = team_losses[team]
ties = team_ties[team]
rankings.append({
'team_key': team,
'record': {
'wins': wins,
'losses': losses,
'ties': ties,
},
'matches_played': wins + losses + ties,
'dq': 0,
'sort_orders': [2 * wins + ties, 0, 0, 0, 0],
'qual_average': None,
})
rankings = sorted(rankings, key=lambda r: -r['sort_orders'][0])
for i, ranking in enumerate(rankings):
ranking['rank'] = i + 1
EventDetailsManipulator.createOrUpdate(EventDetails(
id='2016nytr',
rankings2=rankings,
))
示例11: get
def get(self, event_key):
df = DatafeedFMSAPI('v2.0', save_response=True)
event = Event.get_by_id(event_key)
alliance_selections = df.getEventAlliances(event_key)
event_details = EventDetails(
id=event_key,
alliance_selections=alliance_selections
)
EventDetailsManipulator.createOrUpdate(event_details)
template_values = {'alliance_selections': alliance_selections,
'event_name': event_details.key.id()}
if 'X-Appengine-Taskname' not in self.request.headers: # Only write out if not in taskqueue
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_alliances_get.html')
self.response.out.write(template.render(path, template_values))
示例12: test_createOrUpdate
def test_createOrUpdate(self):
EventDetailsManipulator.createOrUpdate(self.old_event_details)
self.assertOldEventDetails(EventDetails.get_by_id('2011ct'))
EventDetailsManipulator.createOrUpdate(self.new_event_details)
self.assertMergedEventDetails(EventDetails.get_by_id('2011ct'))
示例13: test_findOrSpawn
def test_findOrSpawn(self):
self.old_event_details.put()
self.assertMergedEventDetails(EventDetailsManipulator.findOrSpawn(self.new_event_details))
示例14: get
def get(self, event_key):
if tba_config.CONFIG["env"] == "prod": # disable in prod for now
logging.error("Tried to restore {} from CSV in prod! No can do.".format(event_key))
return
event = Event.get_by_id(event_key)
# alliances
result = urlfetch.fetch(self.ALLIANCES_URL.format(event.year, event_key, event_key))
if result.status_code != 200:
logging.warning('Unable to retreive url: ' + (self.ALLIANCES_URL.format(event.year, event_key, event_key)))
else:
data = result.content.replace('frc', '')
alliance_selections = CSVAllianceSelectionsParser.parse(data)
event_details = EventDetails(
id=event_key,
alliance_selections=alliance_selections
)
EventDetailsManipulator.createOrUpdate(event_details)
# awards
result = urlfetch.fetch(self.AWARDS_URL.format(event.year, event_key, event_key))
if result.status_code != 200:
logging.warning('Unable to retreive url: ' + (self.AWARDS_URL.format(event.year, event_key, event_key)))
else:
# convert into expected input format
data = StringIO.StringIO()
writer = csv.writer(data, delimiter=',')
for row in csv.reader(StringIO.StringIO(result.content), delimiter=','):
writer.writerow([event.year, event.event_short, row[1], row[2].replace('frc', ''), row[3]])
awards = []
for award in CSVAwardsParser.parse(data.getvalue()):
awards.append(Award(
id=Award.render_key_name(event.key_name, award['award_type_enum']),
name_str=award['name_str'],
award_type_enum=award['award_type_enum'],
year=event.year,
event=event.key,
event_type_enum=event.event_type_enum,
team_list=[ndb.Key(Team, 'frc{}'.format(team_number)) for team_number in award['team_number_list']],
recipient_json_list=award['recipient_json_list']
))
AwardManipulator.createOrUpdate(awards)
# matches
result = urlfetch.fetch(self.MATCHES_URL.format(event.year, event_key, event_key))
if result.status_code != 200:
logging.warning('Unable to retreive url: ' + (self.MATCHES_URL.format(event.year, event_key, event_key)))
else:
data = result.content.replace('frc', '').replace('{}_'.format(event_key), '')
match_dicts, _ = OffseasonMatchesParser.parse(data)
matches = [
Match(
id=Match.renderKeyName(
event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=event.key,
year=event.year,
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None)
)
for match in match_dicts]
MatchManipulator.createOrUpdate(matches)
# rankings
result = urlfetch.fetch(self.RANKINGS_URL.format(event.year, event_key, event_key))
if result.status_code != 200:
logging.warning('Unable to retreive url: ' + (self.RANKINGS_URL.format(event.year, event_key, event_key)))
else:
# convert into expected input format
rankings = list(csv.reader(StringIO.StringIO(result.content), delimiter=','))
event_details = EventDetails(
id=event_key,
rankings=rankings
)
EventDetailsManipulator.createOrUpdate(event_details)
self.response.out.write("Done restoring {}!".format(event_key))
示例15: test_updateMerge
def test_updateMerge(self):
self.assertMergedEventDetails(EventDetailsManipulator.updateMerge(self.new_event_details, self.old_event_details))