def get(self, event_key):
        df = DatafeedUsfirst()

        event = Event.get_by_id(event_key)
        new_matches = MatchManipulator.createOrUpdate(df.getMatches(event))

        if new_matches:
            for match in new_matches:
                if hasattr(match, 'dirty') and match.dirty:
                    # Enqueue push notification
                    try:
                        FirebasePusher.updated_event(event.key_name)
                    except:
                        logging.warning("Enqueuing Firebase push failed!")
                    # Enqueue task to calculate matchstats
                    taskqueue.add(
                            url='/tasks/math/do/event_matchstats/' + event.key_name,
                            method='GET')
                    break


        template_values = {
            'matches': new_matches,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_matches_get.html')
        self.response.out.write(template.render(path, template_values))
コード例 #2
0
    def get(self, event_key):
        df = DatafeedUsfirst()

        event = Event.get_by_id(event_key)
        new_matches = MatchManipulator.createOrUpdate(df.getMatches(event))

        if new_matches:
            for match in new_matches:
                if hasattr(match, 'dirty') and match.dirty:
                    # Enqueue push notification
                    try:
                        FirebasePusher.updated_event(event.key_name)
                    except:
                        logging.warning("Enqueuing Firebase push failed!")
                    # Enqueue task to calculate matchstats
                    taskqueue.add(
                            url='/tasks/math/do/event_matchstats/' + event.key_name,
                            method='GET')
                    break


        template_values = {
            'matches': new_matches,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_matches_get.html')
        self.response.out.write(template.render(path, template_values))
コード例 #3
0
class TestDatafeedUsfirstMatches(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_urlfetch_stub()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()

        self.datafeed = DatafeedUsfirst()

    def tearDown(self):
        self.testbed.deactivate()

    def test_getMatchResultsList(self):
        event = Event(id="2011ct", event_short="ct", year=2011)

        matches = self.datafeed.getMatches(event)

        # Test 2011ct_qm1
        match = matches[0]
        self.assertEqual(match.comp_level, "qm")
        self.assertEqual(match.set_number, 1)
        self.assertEqual(match.match_number, 1)
        self.assertEqual(
            match.team_key_names,
            [u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'])
        self.assertEqual(
            match.alliances_json,
            """{"blue": {"score": 57, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": 74, "teams": ["frc69", "frc571", "frc176"]}}"""
        )
        self.assertEqual(match.time_string, "9:29 AM")

        # Test 2011ct_qf2m3
        match = matches[-7]
        self.assertEqual(match.comp_level, "qf")
        self.assertEqual(match.set_number, 2)
        self.assertEqual(match.match_number, 3)
        self.assertEqual(match.team_key_names, [
            u'frc716', u'frc3125', u'frc181', u'frc1699', u'frc1124', u'frc714'
        ])
        self.assertEqual(
            match.alliances_json,
            """{"blue": {"score": 74, "teams": ["frc1699", "frc1124", "frc714"]}, "red": {"score": 90, "teams": ["frc716", "frc3125", "frc181"]}}"""
        )
        self.assertEqual(match.time_string, "2:05 PM")

        # Test 2011ct_f1m2
        match = matches[-1]
        self.assertEqual(match.comp_level, "f")
        self.assertEqual(match.set_number, 1)
        self.assertEqual(match.match_number, 2)
        self.assertEqual(match.team_key_names, [
            u'frc195', u'frc1923', u'frc155', u'frc177', u'frc175', u'frc1073'
        ])
        self.assertEqual(
            match.alliances_json,
            """{"blue": {"score": 65, "teams": ["frc177", "frc175", "frc1073"]}, "red": {"score": 97, "teams": ["frc195", "frc1923", "frc155"]}}"""
        )
        self.assertEqual(match.time_string, "3:23 PM")
コード例 #4
0
    def get(self, event_key):
        df = DatafeedUsfirst()

        event = Event.get_by_id(event_key)
        new_matches = MatchManipulator.createOrUpdate(df.getMatches(event))

        template_values = {
            'matches': new_matches,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_matches_get.html')
        self.response.out.write(template.render(path, template_values))
コード例 #5
0
class TestDatafeedUsfirstMatches(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_urlfetch_stub()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        
        self.datafeed = DatafeedUsfirst()
    
    def tearDown(self):
        self.testbed.deactivate()
    
    def test_getMatchResultsList(self):
        event = Event(
          id = "2011ct",
          event_short = "ct",
          year = 2011
        )
        
        matches = self.datafeed.getMatches(event)
        
        # Test 2011ct_qm1
        match = matches[0]
        self.assertEqual(match.comp_level, "qm")
        self.assertEqual(match.set_number, 1)
        self.assertEqual(match.match_number, 1)
        self.assertEqual(match.team_key_names, [u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'])
        self.assertEqual(match.alliances_json, """{"blue": {"score": 57, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": 74, "teams": ["frc69", "frc571", "frc176"]}}""")
        self.assertEqual(match.time_string, "9:29 AM")

        # Test 2011ct_qf2m3
        match = matches[-7]
        self.assertEqual(match.comp_level, "qf")
        self.assertEqual(match.set_number, 2)
        self.assertEqual(match.match_number, 3)
        self.assertEqual(match.team_key_names, [u'frc716', u'frc3125', u'frc181', u'frc1699', u'frc1124', u'frc714'])
        self.assertEqual(match.alliances_json, """{"blue": {"score": 74, "teams": ["frc1699", "frc1124", "frc714"]}, "red": {"score": 90, "teams": ["frc716", "frc3125", "frc181"]}}""")
        self.assertEqual(match.time_string, "2:05 PM")

        # Test 2011ct_f1m2
        match = matches[-1]
        self.assertEqual(match.comp_level, "f")
        self.assertEqual(match.set_number, 1)
        self.assertEqual(match.match_number, 2)
        self.assertEqual(match.team_key_names, [u'frc195', u'frc1923', u'frc155', u'frc177', u'frc175', u'frc1073'])
        self.assertEqual(match.alliances_json, """{"blue": {"score": 65, "teams": ["frc177", "frc175", "frc1073"]}, "red": {"score": 97, "teams": ["frc195", "frc1923", "frc155"]}}""")
        self.assertEqual(match.time_string, "3:23 PM")
コード例 #6
0
    def get(self, event_key):
        df = DatafeedUsfirst()

        event = Event.get_by_id(event_key)
        new_matches = MatchManipulator.createOrUpdate(df.getMatches(event))

        try:
            last_matches = MatchHelper.recentMatches(new_matches, 1)
            upcoming_matches = MatchHelper.upcomingMatches(new_matches, 8)
        except:
            logging.warning("Computing last/upcoming matches for Firebase failed!")
        try:
            FirebasePusher.updateEvent(event, last_matches, upcoming_matches)
        except:
            logging.warning("Enqueuing Firebase push failed!")

        template_values = {
            'matches': new_matches,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_matches_get.html')
        self.response.out.write(template.render(path, template_values))