def get(self):
        user = users.User('stats@2cloudproject.com')
        try:
            user_data = models.getUser(user)
        except models.UserDoesNotExistError:
            user_data = models.UserData(user=user).save()
        try:
            device = models.getDevice("%s/%s" % (user.email(), "Web"))
        except models.DeviceDoesNotExistError:
            device = models.DeviceData(user=user_data,
                    name="Web").save()
        channel = channels.Channel(device.address, override_quota=True)
        path = os.path.join(os.path.dirname(__file__), 'dashboard.html')
        stats_data = models.StatsData.all().order("-date").fetch(1000)
        template_values = {
                'channel_id': channel.token,
                'stats': {}
        }
        stats = template_values['stats']
        for datapoint in stats_data:
            datestamp = int(time.mktime(
                datapoint.date.date().timetuple()) * 1000)
            hour = datapoint.date.hour
            if datestamp not in stats:
                stats[datestamp] = {
                        'datestamp': datestamp,
                        'date': datapoint.date,
                        'datapoints': {}
                    }
            if datapoint.datapoint not in stats[datestamp]['datapoints']:
                stats[datestamp]['datapoints'][datapoint.datapoint] = {
                        'datapoint': datapoint.datapoint,
                        'values': {}
                    }
            point_id = "%s" % hour
            if datapoint.duration == "day":
                point_id = "total"
            dp = datapoint.datapoint
            stats[datestamp]['datapoints'][dp]['values'][point_id] = {
                    'datapoint': datapoint.datapoint,
                    'datestamp': datestamp,
                    'hour':      hour,
                    'count':     int(datapoint.count),
                    'duration':  datapoint.duration
            }
        template_values['stats'] = stats
        logging.info(template_values)
        self.response.out.write(template.render(path, template_values))
dataset/ETHPy150Open 2cloud/AppEngine/devlinks.py/StatsDashboard.get/original