当前位置: 首页>>代码示例>>Python>>正文


Python Report.query方法代码示例

本文整理汇总了Python中models.Report.query方法的典型用法代码示例。如果您正苦于以下问题:Python Report.query方法的具体用法?Python Report.query怎么用?Python Report.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Report的用法示例。


在下文中一共展示了Report.query方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reportsv1

# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import query [as 别名]
def reportsv1():
    if not request.args or not request.args['key'] or request.args['key'] != IOS_API_KEY:
        abort(401)
    if request.method == "POST":
        if not request.json or not 'google_places_id' in request.json or not 'crowd_level' in request.json:
            abort(400)
        report = Report(
                        google_places_id=request.json['google_places_id'],
                        crowd_level=request.json['crowd_level'])
        if 'comments' in request.json:
            report.populate(comments=request.json['comments'])
        if 'ios_device_id' in request.json:
            report.populate(ios_device_id=request.json['ios_device_id'])
        if 'photo_url' in request.json:
            report.populate(photo_url=request.json['photo_url'])
        try:
            # report.put()
            return jsonify(report.to_dict())
        except CapabilityDisabledError:
            abort(400)
    if len(request.args) == 1:
        reports = Report.query().order(-Report.created_at).fetch(20)
        return jsonify({"reports": [report.to_dict() for report in reports]})
    if len(request.args) > 2:
        abort(400)
    if not request.args['google_places_id']:
        abort(400)
    google_places_id = request.args['google_places_id']
    reports = Report.query(Report.google_places_id==google_places_id).order(-Report.created_at).fetch(20)
    return jsonify({"reports": [report.to_dict() for report in reports]})
开发者ID:kcmoffat,项目名称:bumpn-backend,代码行数:32,代码来源:views.py

示例2: get

# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import query [as 别名]
    def get(self):

        # Check if datasets are loaded in datastore

        # Items in datastore
        d = Dataset.query().count()
        # Items in CDB
        q = "select count(*) as c from resource_staging" + \
            " where ipt is true and networks like '%VertNet%';"
        c = cartodb_query(q)[0]['c']

        # Number of reports stored in the datastore
        num_reports = Report.query().count()

        periods = Period.query()
        num_periods = periods.count()

        periods_done = Period.query(Period.status == "done")
        num_periods_done = periods_done.count()

        periods_progress = Period.query(Period.status == "in progress")
        num_periods_progress = periods_progress.count()

        periods_failed = Period.query(Period.status == "failed")
        num_periods_failed = periods_failed.count()

        resp = {
            "Datastore integrity": [
                {"Datasets in CartoDB": c},
                {"Datasets in the Datastore": d}
            ],
            "Report periods": [
                {"Stored periods": num_periods},
                {"Stored reports": num_reports},
                {"Periods completed": num_periods_done},
                {"Periods in progress": num_periods_progress},
                {"Periods failed": num_periods_failed},
            ]
        }

        if c != d or c == 0:
            dataset_setup_url = "http://%s/setup_datasets" % _HOSTNAME
            resp["Datastore integrity"].append({"URL for dataset setup": dataset_setup_url})
        if num_periods > 0:
            links_to_periods = ["http://%s/status/period/%s" % (_HOSTNAME, x.key.id()) for x in periods.fetch()]
            resp["Report periods"].append({"Links to periods": links_to_periods})
        if num_periods_done > 0:
            resp['Report periods'].append({'List of periods done': [x.period.strftime("%Y-%m") for x in periods_done.fetch()]})
        if num_periods_progress > 0:
            resp['Report periods'].append({'List of periods in progress': [x.period.strftime("%Y-%m") for x in periods_progress.fetch()]})
        if num_periods_failed > 0:
            resp['Report periods'].append({'List of periods failed': [x.period.strftime("%Y-%m") for x in periods_failed.fetch()]})

        self.response.headers['content-type'] = "application/json"
        self.response.write(json.dumps(resp))
开发者ID:VertNet,项目名称:usagestats,代码行数:57,代码来源:Status.py

示例3: get

# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import query [as 别名]
 def get(self):
     from models import Report
     cutoff = datetime.now() - timedelta(days=30)
     old_reports = Report.query().filter(Report.dt_created < cutoff).fetch(limit=None)
     n = 0
     if old_reports:
         for report in old_reports:
             try:
                 report.clean_delete(self_delete=False)
             except Exception, e:
                 logging.info(str(e))
         n = len(old_reports)
         ndb.delete_multi([dr.key for dr in old_reports])
开发者ID:akatsoulas,项目名称:flow-dashboard,代码行数:15,代码来源:tasks.py

示例4: post

# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import query [as 别名]
    def post(self):
        user = users.get_current_user()
        if user:
            # data = json.loads(self.request.body)
            reports = Report.query(Report.author == user).fetch()

            # json_query_data = JSONEncoder().encode(reports)
            result = {
                'result': reports,
                'total': len(reports)
            }
            self.response.headers['Content-Type'] = 'application/json'
            self.response.write(JSONEncoder().encode(result))
开发者ID:htomika,项目名称:gaeFeedFind,代码行数:15,代码来源:main.py

示例5: get

# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import query [as 别名]
    def get(self, gbifdatasetid):

        dataset_key = ndb.Key("Dataset", gbifdatasetid)

        query = Report.query(Report.reported_resource == dataset_key)
        query = query.order(-Report.reported_period)
        report_keys = query.fetch(keys_only=True)

        period_list = [
            {
                "text": x.id().split("|")[0][:4]+"-"+x.id().split("|")[0][4:],
                "url": x.id().split("|")[0]
            } for x in report_keys]

        template = JINJA_ENVIRONMENT.get_template('dataset.html')
        self.response.write(template.render(
            dataset=dataset_key.get(),
            period_list=period_list,
            periods=len(period_list)
        ))
开发者ID:VertNet,项目名称:usagestats,代码行数:22,代码来源:DatasetViewer.py

示例6: get

# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import query [as 别名]
    def get(self):
        # Checks for active Google account session
        user = users.get_current_user()

        if user:
            reports_query = Report.query(Report.author == user).order(-Report.date)
            reports = reports_query.fetch(10)
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        template_values = {
            'reports': reports,
            'url': url,
            'url_linktext': url_linktext,
        }

        template = JINJA_ENVIRONMENT.get_template('index.html')
        self.response.write(template.render(template_values))
开发者ID:htomika,项目名称:gaeFeedFind,代码行数:23,代码来源:main.py

示例7: post

# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import query [as 别名]
    def post(self):

        # Get parameters from memcache
        memcache_keys = ["period", "testing"]
        params = memcache.get_multi(memcache_keys,
                                    key_prefix="usagestats_parser_")

        # Try to get 'params' from memcache
        try:
            self.period = params['period']
        # If not in memcache (i.e., if called directly), get from request
        except KeyError:
            self.period = self.request.get("period")

        # If still not there, halt
        if not self.period:
            self.error(400)
            resp = {
                "status": "error",
                "message": "Period parameter was not provided."
            }
            logging.error(resp)
            self.response.write(json.dumps(resp)+"\n")
            return
        else:
            memcache.set("usagestats_parser_period", self.period)

        # If Period not already stored, halt
        period_key = ndb.Key("Period", self.period)
        period_entity = period_key.get()
        if not period_entity:
            self.error(400)
            resp = {
                "status": "error",
                "message": "Provided period does not exist in datastore",
                "data": {
                    "period": self.period
                }
            }
            logging.error(resp)
            self.response.write(json.dumps(resp)+"\n")
            return

        # Try to get 'testing' from memcache
        try:
            self.testing = params['testing']
        # If not in memcache (i.e., if called directly), get from request
        except KeyError:
            self.testing = self.request.get('testing').lower() == 'true'

        # Prepare list of reports to store
        logging.info("Getting list of reports to send issue")

        # Base query
        reports_q = Report.query()

        # Only Reports for current Period
        reports_q = reports_q.filter(Report.reported_period == period_key)

        # Only those with 'issue_sent' property set to False
        reports_q = reports_q.filter(Report.issue_sent == False)

        # Store final query
        reports_query = reports_q

        logging.info("Found %d Reports to send issue" % reports_query.count())

        # Get cursor from request, if any
        cursor_str = self.request.get("cursor", None)
        cursor = None
        if cursor_str:
            cursor = ndb.Cursor(urlsafe=cursor_str)
            logging.info("Cursor built: %s" % cursor)

        # Initialize loop
        more = True

        # Loop until DeadlineExceededError
        try:
            # or until no more reports left
            while more is True:

                # Get next (or first) round of results
                report, new_cursor, more = reports_query.fetch_page(
                    PAGE_SIZE, start_cursor=cursor
                )

                # Send issue
                self.send_issue(report[0])

                if more is True:
                    cursor = new_cursor

            logging.info("Finished creating all issues")

            resp = {
                "status": "success",
                "message": "Successfully finished creating all issues",
            }

#.........这里部分代码省略.........
开发者ID:VertNet,项目名称:usagestats,代码行数:103,代码来源:GitHubIssue.py

示例8: initialize_extraction

# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import query [as 别名]
    def initialize_extraction(self, period=None, force=None):
        """Check if Period parameter is valid, if the Period entity already exists
and create a new Period."""
        self.response.headers['Content-Type'] = "application/json"

        # Check that 'period' is provided
        if not self.period:
            logging.error("Period not found on POST body. Aborting.")
            self.error(400)
            resp = {
                "status": "error",
                "message": "Period not found on POST body. " +
                           "Aborting."
            }
            self.response.write(json.dumps(resp) + "\n")
            return 1

        # Check that 'period' is valid
        if len(self.period) != 6:
            self.error(400)
            resp = {
                "status": "error",
                "message": "Malformed period. Should be YYYYMM (e.g., 201603)"
            }
            self.response.write(json.dumps(resp) + "\n")
            return 1

        # Get existing period
        period_key = ndb.Key("Period", self.period)
        period_entity = period_key.get()

        # If existing, abort or clear and start from scratch
        if period_entity:
            if self.force is not True:
                logging.error("Period %s already exists. " % self.period +
                              "Aborting. To override, use 'force=true'.")
                resp = {
                    "status": "error",
                    "message": "Period %s already exists. " % self.period +
                               "Aborting. To override, use 'force=true'."
                }
                self.response.write(json.dumps(resp) + "\n")
                return 1
            else:
                logging.warning("Period %s already exists. " % self.period +
                                "Overriding.")
                # Delete Reports referencing period
                r = Report.query().filter(Report.reported_period == period_key)
                to_delete = r.fetch(keys_only=True)
                logging.info("Deleting %d Report entities" % len(to_delete))
                deleted = ndb.delete_multi(to_delete)
                logging.info("%d Report entities removed" % len(deleted))

                # Delete Period itself
                logging.info("Deleting Period %s" % period_key)
                period_key.delete()
                logging.info("Period entity deleted")

        # Create new Period (id=YYYYMM)
        logging.info("Creating new Period %s" % self.period)
        y, m = (int(self.period[:4]), int(self.period[-2:]))
        p = Period(id=self.period)
        p.year = y
        p.month = m
        p.status = 'in progress'
        period_key = p.put()

        # Check
        if period_key:
            logging.info("New Period %s created successfully." % self.period)
            logging.info("New period's key = %s" % period_key)
        else:
            self.error(500)
            logging.error("Could not create new Period %s" % self.period)
            resp = {
                "status": "error",
                "message": "Could not create new Period %s" % self.period
            }
            self.response.write(json.dumps(resp) + "\n")
            return 1

        # Clear temporary entities
        keys_to_delete = ReportToProcess.query().fetch(keys_only=True)
        logging.info("Deleting %d temporal (internal use only) entities"
                     % len(keys_to_delete))
        ndb.delete_multi(keys_to_delete)

        return 0
开发者ID:VertNet,项目名称:usagestats,代码行数:90,代码来源:InitExtraction.py


注:本文中的models.Report.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。