def postReport(request): if request.method == 'POST': # print request.POST # print request.POST.get('additionalComments') categoryObject = Category.objects.get( animal_type=request.POST.get('animalType')) latitude = request.POST.get('latitude') longitude = request.POST.get('longitude') mobile_number = request.POST.get('mobileNumber') image_path = request.POST.get('imagePath') additional_comments = request.POST.get('additionalComments') webUrl = ( "http://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s" % (latitude, longitude)) urlstream = urllib2.urlopen(webUrl, timeout=1) data = json.loads(urlstream.read()) location = data['results'][0]["formatted_address"] reportObject = Report(animal_type_id=categoryObject.id, latitude=latitude, longitude=longitude, mobile_number=mobile_number, image_path=image_path, location=location, additional_comments=additional_comments) reportObject.save() return HttpResponse(reportObject.id)
def test_reports_yelp_business_detail(self): """Test that calling business detail on a business that has reports written about it includes details about that business. # TODO: MOCK out actual yelp API call.""" u1 = User.register(email='*****@*****.**', username='******', password='******') Business.create( name='Cuisine of Nepal', longitude=-122.42318, latitude=37.74097, id='iUockw0CUssKZLyoGJYEXA', city='San Francisco', state='CA', country='US') db.session.commit() Report.create(user_id=u1.id, text='Good fud.', business_id='iUockw0CUssKZLyoGJYEXA') db.session.commit() with self.client as c: resp = c.get( '/v1/business_detail/iUockw0CUssKZLyoGJYEXA?name=Cuisine+of+Nepal&latlng=37.74097,-122.42318') # noqa e501 data = resp.get_json() self.assertEqual(resp.status_code, 200) self.assertIn('reports', data) self.assertEqual(data['reports'][0]['text'], 'Good fud.')
def setUp(self): self.user = User.register(email="*****@*****.**", username="******", password="******") self.mission = Mission.create(editor=self.user.id, name="test mission", city="Albany", state="NY", country='US') self.business = Business.create(name='Cuisine of Nepal', longitude=-122.42318, latitude=37.74097, id='iUockw0CUssKZLyoGJYEXA', city='San Francisco', state='CA', country='US') self.mission.businesses.append(self.business) self.report = Report.create(user_id=self.user.id, business_id='iUockw0CUssKZLyoGJYEXA', text='Best nepalese food I ever had!') db.session.commit() self.report2 = Report.create(user_id=self.user.id, mission_id=self.mission.id, text='The curry was devine!') db.session.commit()
def on_get(self, req, resp): user = req.context['user'] if 'id' in req.params: post_id = req.params['id'] try: post = Post.find_by_id(self.session, re.match("^\d+", post_id).group(0)) except NoResultFound: resp.media = error('no post') return except: resp.media = error('no post') if post.author == user['user_id'] or user['level'] == ADMIN_LEVEL: # reporting process try: report = Report.find_by_author(self.session, user['user_id']) now = datetime.datetime.utcnow() if (report.report_time + datetime.timedelta(0, RATE_LIMIT_DELTA)).time() > now.time(): resp.media = error('rate limit reached') return except NoResultFound: pass report = Report(post=post_id, author=post.author) self.session.add(report) self.session.commit() resp.media = result('success') else: resp.media = error('permission denied') else: resp.media = error('id')
def test_parse_report(self): response = ''' {"response":[ {"clicks":"103","money":"1000.00","day":"2010-10-08","campaign_id":123,"client_id":123,"client_name":"Ford","campaign_name":"Campaign1","ctr":"0.199","impressions":"51635"} ]} ''' account = Account.objects.create(remote_id=1) Campaign.objects.create(account=account, remote_id=123, fetched=datetime.now()) Client.objects.create(account=account, remote_id=123, fetched=datetime.now()) instance = Report(time_from=datetime.now(), time_to=datetime.now()) instance.parse(json.loads(response)['response'][0]) instance.save() self.assertTrue(isinstance(instance.campaign, Campaign)) self.assertEqual(instance.campaign.remote_id, 123) self.assertTrue(isinstance(instance.client, Client)) self.assertEqual(instance.client.remote_id, 123) self.assertEqual(instance.clicks, 103) self.assertEqual(instance.impressions, 51635) self.assertEqual(instance.day, date(2010,10,8)) self.assertEqual(instance.client_name, "Ford") self.assertEqual(instance.campaign_name, "Campaign1") self.assertEqual(instance.money, '1000.00') self.assertEqual(instance.ctr, '0.199')
def summarize(): report = Report() if request.method == 'POST': start = request.form['start'] end = request.form['end'] paging, data_list = report.summary(start=start, end=end) # https://github.com/Shir0kamii/Flask-CSV if data_list: encoding = 'utf-8-sig' filename = start + '_' + end + '.csv' buf = StringIO() writer = ValidatedWriter(buf, fieldnames=data_list[0].keys()) writer.writeheader() for data in data_list: writer.writerow(data) buf.seek(0) buf = BytesIO(buf.read().encode(encoding)) return send_file(buf, attachment_filename=filename, as_attachment=True, mimetype='text/csv') form = PeriodSubmitForm() page, _, start, end = request_get(request.args) paging, data_list = report.summary(page=page, start=start, end=end) return render_template('report/summary.html', **locals())
def add_report(desc, user_id, user_informed): report = Report(description=desc, user=user_id, user_informed=user_informed, status='new', date_created=datetime.datetime.now()) return report.save()
def attend(): report = Report() if request.method == 'POST': start = request.form['start'] end = request.form['end'] name = request.form['name'] data_list = report.attend(page='all', name=name, start=start, end=end) if data_list: encoding = 'utf-8-sig' filename = start + '_' + end + '.csv' buf = StringIO() writer = ValidatedWriter(buf, fieldnames=data_list[0].keys()) writer.writeheader() for data in data_list: writer.writerow(data) buf.seek(0) buf = BytesIO(buf.read().encode(encoding)) return send_file(buf, attachment_filename=filename, as_attachment=True, mimetype='text/csv') # https://gist.github.com/doobeh/3e685ef25fac7d03ded7#file-vort-html-L11 form = PeriodSubmitForm() page, name, start, end = request_get(request.args) paging, today, data_list, summary = report.attend(page=page, name=name, start=start, end=end) return render_template('report/attendance.html', **locals())
def home(cell_path=None): import sys logging.info("Version python: "+sys.version); maps = memcache.get('default_maps') if maps: maps = json.loads(maps) else: maps = default_maps() memcache.add(key='default_maps', value=json.dumps(maps), time=60*10) # send only the active report reports = json.dumps([Report.current().as_dict()]) report_base = json.dumps([Report.current().previous().as_dict()]) logging.info("Reports: "+str(reports)) logging.info("Maps: "+str(maps)) u = get_or_create_user() if not u: abort(403) logout_url = users.create_logout_url('/') return render_template('home.html', reports_json=reports, report_base_json=report_base, user=u, maps=maps, polygons_table=settings.FT_TABLE_ID, logout_url=logout_url)
def serve(self, d): import cloudstorage as gcs rkey = self.request.get('rkey') r = Report.GetAccessible(rkey, self.user, urlencoded_key=True) if r: if r.is_done() and r.gcs_files: gcsfn = r.gcs_files[0] if tools.on_dev_server(): try: gcs_file = gcs.open(gcsfn, 'r') except gcs.NotFoundError, e: self.response.out.write("File not found") else: self.response.headers[ 'Content-Type'] = Report.content_type(r.extension) self.response.headers['Content-Disposition'] = str( 'attachment; filename="%s"' % r.filename()) self.response.write(gcs_file.read()) gcs_file.close() else: signed_url = tools.sign_gcs_url(gcsfn, expires_after_seconds=5) response = self.redirect(signed_url) logging.info(response) else: self.set_response(success=False, status=404, message="Report not ready") # Not found
def test_create_report(self): r = Report(author=Account.objects.first(), start_period=self.today, end_period=self.today, scope="maintenance_review") r.save() self.assertEqual(Report.objects.all().count(), 2)
def save_db(): report = Report() report.update() # report.update(date='2021-10-11') t = threading.Timer(1800, save_db) app.logger.info('save_db') t.daemon = True t.start()
def test_one_report(self): client = Client(product=ProductData.killerapp_obj, cookie='123') client.put() report = Report(product=ProductData.killerapp_obj, client=client, status=REPORT_NEW, remote_ip='127.0.0.1', data='[]') report.put() response = self.get('/status/') assert 'Queued Reports: 1' in str(response)
def updateReport(self, id, fieldsToUpdate, params): # update the report with the specified id, indicating which fields to update and what to update them to db.updateObject('reports', id, fieldsToUpdate, params) # retrieve the newly updated report and create an object from it's data reportTuple = db.getObjectById('reports', id)[0] report = Report(reportTuple[0], self.__getCar(reportTuple[1]), reportTuple[2], reportTuple[3]) # jsonify the report to confirm the update return jsonify({'report': report.asDict()})
def mutate(self, info, report_data=None): report = Report(reported_id_type=report_data.reported_id_type, reported_id=report_data.reported_id, user_id=report_data.user_id, reason=report_data.reason, description=report_data.description) report.save() return CreateReportMutation(report=report)
def test_model_chart(self): "Test Chart Model" report = Report(name='test') report.save() obj = Chart(name='test', report=report) obj.save() self.assertEquals('test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
def testing(): r = Report.current() r = Report.get(Key('ahBpbWF6b24tcHJvdG90eXBlcg4LEgZSZXBvcnQYiaECDA')) logging.info("report " + unicode(r)) ee_resource = 'MOD09GA' ndfi = NDFI(ee_resource, r.comparation_range(), r.range()) #return str(ndfi.mapid2()) return str(ndfi.freeze_map(1089491, r.key().id()))
def test_fetch_and_delete(self): self.post_json("/api/report/generate", {'type': REPORT.TASK_REPORT}, headers=self.api_headers) self.execute_tasks_until_empty() reports = Report.Fetch(self.u) self.assertEqual(len(reports), 1) # Delete reports[0].clean_delete() reports = Report.Fetch(self.u) self.assertEqual(len(reports), 0)
def cpanel_open(request): user = request.user device_choices = Device.get_device_choices(Device()) os_choices = Device.get_os_choices(Device()) problem_choices = Report.get_problem_choices(Report()) return render_to_response('cpanel/open.html', { 'user': user, 'device_choices': device_choices, 'os_choices': os_choices, 'problem_choices': problem_choices }, context_instance=RequestContext(request))
def save_quick_report(): body = request.get_json() report = Report(address=body.get('address'), category='דיווח מהיר', description=body.get('transcript')) if current_user.team_id: report.team_id = current_user.team_id db.session.add(report) db.session.commit() if not current_user.is_admin: create_new_notification(1, report) return jsonify({'id': report.id})
def user_report(request): ''' report handle ''' if request.method == "POST": rep_id = request.POST.get("rep_id","") rep_type = request.POST.get("rep_type","") reason = request.POST.get("reason","") if rep_id == '' or rep_type == '' or reason == '': return HttpResponse(-3) report = Report(rep_type=int(rep_type),beReported=rep_id,reason=reason) report.save() return HttpResponse(0)
def on_get(self, req, resp): user = req.context['user'] if not user['level'] == ADMIN_LEVEL: reports = Report.get_reports_by_author_id(self.session, user['user_id']) rr = [{"id":r.id, 'post_id': r.post, 'msg': r.msg, 'checked': r.checked} for r in reports] resp.media = result(rr) return reports = Report.get_reports(self.session) rr = [{"id":r.id, 'post_id': r.post, 'msg': r.msg} for r in reports] resp.media = result(rr) return
def mission_reports(): """Mission reports view.""" query_params = request.args.to_dict() if not query_params: reports = Report.get_by_recent() else: reports = Report.search(query_params) return render_template('main_views/reports.html', reports=reports, form_data=query_params)
def user_report(request): ''' report handle ''' if request.method == "POST": rep_id = request.POST.get("rep_id", "") rep_type = request.POST.get("rep_type", "") reason = request.POST.get("reason", "") if rep_id == '' or rep_type == '' or reason == '': return HttpResponse(-3) report = Report(rep_type=int(rep_type), beReported=rep_id, reason=reason) report.save() return HttpResponse(0)
def test_get_by_recent(self): report3 = Report.create(user_id=self.user.id, business_id='iUockw0CUssKZLyoGJYEXA', text='The curry was devine!') db.session.commit() report3.submitted_on = datetime.utcnow() db.session.commit() recent = Report.get_by_recent() self.assertEqual(len(recent), 3) self.assertEqual(recent[0], report3)
def home(cell_path=None): maps = memcache.get('default_maps') if maps: maps = json.loads(maps) else: maps = default_maps() memcache.add(key='default_maps', value=json.dumps(maps), time=3600*24) # send only the active report reports = json.dumps([Report.current().as_dict()]) user = users.get_current_user() u = User.get_user(user) if not u and users.is_current_user_admin(): u = User(user=user, role='admin') u.put() if not u: abort(403) logout_url = users.create_logout_url('/') return render_template('home.html', reports_json=reports, user=u, maps=maps, logout_url=logout_url)
def parse(self): xpath_ = "//*[@id='ctl00_ContentPlaceHolder1_Name_Reports1_TabContainer1_TabPanel1_dgReports']/tbody/tr[@class!='gridviewheader']" tree = html.fromstring(self.page_content) body = tree.xpath(xpath_) logging.info(body) links = [] reports = [] if body is None: return [ (), ] for tr in body: try: link = tr.xpath('.//td[1]/a/@id').pop() report_type = tr.xpath('.//td[2]/span/text()').pop() year = tr.xpath('.//td[3]/text()').pop() report_filed_date = tr.xpath('.//td[4]/text()').pop() report_received_by = tr.xpath('.//td[5]/span/text()').pop() report_received_date = tr.xpath('.//td[6]/span/text()').pop() links.append(link) report = Report(report_type=report_type, year=year, report_filed_date=report_filed_date, report_received_by=report_received_by, report_received_date=report_received_date) reports.append(report) except Exception as e: logging.info(e) return ((link, report) for link, report in zip(links, reports))
def cancellation(self): buy = self.buy reports = Report.select().where(Report.buy == buy) list_error = [(check_befor_update_data(report)) for report in reports] if list_error == [] or list_error == [[]]: reply = QMessageBox.question( self, "Confirmation", "<h3 style='color:red;'>Voulez vous" " vraiment annuler ce rapport" " d'achat?</h3>", QMessageBox.Yes | QMessageBox.No, QMessageBox.No, ) if reply == QMessageBox.Yes: from ui.dashboard import DashbordViewWidget buy.deletes_data() self.change_main_context(DashbordViewWidget) else: QMessageBox.about( self, "Alerte", "<h3>Vous ne pousez pas supprimer ce rapport car:</h3>" "<ul><li></li>" " %(err)s" "<li>Après la suppression</li></ul>" % {"err": list_error}, )
def default_maps(): maps = [] r = Report.current() logging.info("report " + unicode(r)) landsat = EELandsat() ndfi = NDFI(past_month_range(r.start), r.range()) d = landsat.mapid(*r.range()) maps.append({'data' :d, 'info': 'LANDSAT/L7_L1T'}) """ d = landsat.mapid(*past_month_range(r.start)) maps.append({'data' :d, 'info': 'LANDSAT/L7_L1T-old'}) """ #d = ndfi.mapid2() #if d: maps.append({'data' :d, 'info': 'ndfi difference'}) d = ndfi.smaid() if d: maps.append({'data': d, 'info': 'SMA'}) d = ndfi.rgb1id() if d: maps.append({'data': d, 'info': 'RGB'}) d = ndfi.ndfi0id() if d: maps.append({'data': d, 'info': 'NDFI T0'}) d = ndfi.ndfi1id() if d: maps.append({'data' :d, 'info': 'NDFI T1'}) d = ndfi.baseline(r.base_map()) if d: maps.append({'data' :d, 'info': 'Baseline'}) d = ndfi.rgb0id() if d: maps.append({'data': d, 'info': 'Previous RGB'}) return maps
def set_data_for(self, value=None): products = [(Product.get(id=rpt.product_id).name) for rpt in Report.select(fn.Distinct(Report.product))] if value: products = [(prod.name) for prod in Product.select().where(Product.name.contains(value)) .where(Product.name << products).order_by(Product.name.desc())] self.data = [(prd, "") for prd in products]
def tiles_sensor(sensor=None): tile_array = [] if request.method == 'POST': return jsonify({'result': 'post method'}) else: if sensor == 'modis': tile_array = [ { 'name': 'h10v09', 'value': 'h10v09'}, { 'name': 'h11v08', 'value': 'h11v08'}, { 'name': 'h11v09', 'value': 'h11v09'}, { 'name': 'h11v10', 'value': 'h11v10'}, { 'name': 'h12v08', 'value': 'h12v08'}, { 'name': 'h12v09', 'value': 'h12v09'}, { 'name': 'h12v10', 'value': 'h12v10'}, { 'name': 'h13v09', 'value': 'h13v09'}, { 'name': 'h13v10', 'value': 'h13v10'} ] r = Report.current() start_date = r.start end_date = r.end #compounddate = '%04d%02d' % (start_date.year, start_date.month) for i in range(len(tile_array)): image_picker = ImagePicker.find_by_period_and_cell(start_date, end_date, tile_array[i]['name']) if image_picker: tile_array[i]['done'] = True else: tile_array[i]['done'] = False return jsonify({'result': tile_array})
def xmlrpc_test_bulk_insert(self, count, same_crackers = False, when=None): if same_crackers and len(self._crackers) < count: logging.debug("Filling static crackers from {} to {}".format(len(self._crackers), count)) for i in xrange(len(self._crackers), count): self._crackers.append(self.random_ip_address()) if when is None: when = time.time() for i in xrange(count): reporter = self.random_ip_address() if same_crackers: cracker_ip = self._crackers[i] else: cracker_ip = self.random_ip_address() logging.debug("Adding report for {} from {} at {}".format(cracker_ip, reporter, when)) yield utils.wait_and_lock_host(cracker_ip) cracker = yield Cracker.find(where=['ip_address=?', cracker_ip], limit=1) if cracker is None: cracker = Cracker(ip_address=cracker_ip, first_time=when, latest_time=when, total_reports=0, current_reports=0) yield cracker.save() yield controllers.add_report_to_cracker(cracker, reporter, when=when) utils.unlock_host(cracker_ip) logging.debug("Done adding report for {} from {}".format(cracker_ip,reporter)) total = yield Cracker.count() total_reports = yield Report.count() returnValue((total,total_reports))
def list(self, d): _max = self.request.get_range('max', max_value=500, default=100) reports = Report.Fetch(self.user, limit=_max) data = { 'reports': [r.json() for r in reports] } self.set_response(data=data, success=True)
def create_marketing_report(channel_id="C022WMH56KA", mode="daily"): spend = ( "Spend", [("FacebookSpend", "SUM"), ("GoogleSpend", "SUM"), ("FunnelSpend", "SUM")], ) leads = ( "Leads", [ ("TotalLeads", "SUM"), ("UniqueLeads", "SUM"), ("PhonesCollected", "SUM"), ("CostPerLead", "AVG", "FunnelSpend", "TotalLeads"), ], ) conversions = ( "Conversions", [ ("AcquiredCustomers", "SUM"), ("FunnelCR", "AVG", "AcquiredCustomers", "PhonesCollected"), ("FunnelRevenue", "SUM"), ("ROAS", "AVG", "FunnelRevenue", "FunnelSpend"), ], ) report = Report.create("Marketing", mode, channel_id) report.add_section(*spend) report.add_section(*leads) report.add_section(*conversions) return report
def default_maps(): maps = [] r = Report.current() logging.info("report " + unicode(r)) landsat = EELandsat(timestamp(r.start), datetime.datetime.now()) ndfi = NDFI(past_month_range(r.start), r.range()) logging.info('Past_month_range: '+str(past_month_range(r.start))+', Range: '+str(r.range)+', Timestamp: '+str(timestamp(r.start))+', Datetime: '+str(datetime.datetime.now()) ) d = landsat.mapid(timestamp(r.start), datetime.datetime.now()) maps.append({'data' :d, 'info': 'LANDSAT/LE7_L1T'}) d = landsat.mapid_landsat8(timestamp(r.start), datetime.datetime.now()) maps.append({'data':d, 'info': 'LANDSAT/LC8_L1T'}) assetid = r.previous().as_dict().get('assetid') logging.info("Assetid :"+str(assetid)) d = ndfi.smaid() if d: maps.append({'data': d, 'info': 'SMA'}) d = ndfi.rgb1id() if d: maps.append({'data': d, 'info': 'RGB'}) d = ndfi.ndfi0id('modis') if d: maps.append({'data': d, 'info': 'NDFI T0 (MODIS)'}) d = ndfi.ndfi1id('modis') if d: maps.append({'data' :d, 'info': 'NDFI T1 (MODIS)'}) d = ndfi.baseline(r.base_map()) if d: maps.append({'data' :d, 'info': 'Baseline'}) d = ndfi.rgb0id() if d: maps.append({'data': d, 'info': 'Previous RGB'}) return maps """
def popup(self, pos): from ui.ligne_edit import EditLigneViewWidget from ui.deleteview import DeleteViewWidget from data_helper import check_befor_update_data row = self.selectionModel().selection().indexes()[0].row() if (len(self.data) - 1) < row: return False menu = QMenu() editaction = menu.addAction("Modifier cette ligne") delaction = menu.addAction("Supprimer cette ligne") action = menu.exec_(self.mapToGlobal(pos)) report = Report.get(id=self.data[row][-1]) if action == editaction: try: self.parent.open_dialog(EditLigneViewWidget, modal=True, table_p=self, report=report) except IndexError: pass if action == delaction: list_error = check_befor_update_data(report) if list_error == []: if len(self.data) < 2: self.parent.cancellation() else: self.parent.open_dialog( DeleteViewWidget, modal=True, obj=report, table_p=self,) else: from Common.ui.util import raise_error raise_error(u"Impossible de supprimer", """<h3>L'article {} :</h3> Aura <b>{}</b> comme dernier restant.""".format( report.product.name, list_error[-1]))
def add_report(report, member_data): #member_match = [(k,m) for k,m in member_data.items() if m['user_id'] == report.user_id] member_match = [] for k, m in member_data.items(): for x in m: if x['user_id'] == report.user_id: member_match.append(x) if len(member_match) > 0: member_reports = member_match[0].get('reports') report_exists = [ r for r in member_reports if report.message_id == r['message_id'] ] if len(report_exists) == 0: report_objects = [] for item in member_reports: rep = Report(member_match[0].get('user_id'), item.get('report_nickname'), item.get('message_id'), item.get('reported_by')) report_objects.append(rep) report_objects.append(report) updated_member = Member(member_match[0]['user_id'], member_match[0]['nickname'], report_objects) return updated_member else: new_reports = [] new_reports.append(report) new_member = Member(report.user_id, report.report_nickname, new_reports) return new_member
def default_maps(): maps = [] r = Report.current() logging.info("report " + unicode(r)) ee_resource = 'MOD09GA' landsat = EELandsat('LANDSAT/L7_L1T') ndfi = NDFI(ee_resource, past_month_range(r.start), r.range()) d = landsat.mapid(*r.range()) if 'data' in d: maps.append({'data' :d['data'], 'info': 'LANDSAT/L7_L1T'}) """ d = landsat.mapid(*past_month_range(r.start)) if 'data' in d: maps.append({'data' :d['data'], 'info': 'LANDSAT/L7_L1T-old'}) """ #d = ndfi.mapid2() #if 'data' in d: #maps.append({'data' :d['data'], 'info': 'ndfi difference'}) d = ndfi.smaid() if 'data' in d: maps.append({'data': d['data'], 'info': 'SMA'}) d = ndfi.rgbid() if 'data' in d: maps.append({'data': d['data'], 'info': 'RGB'}) d = ndfi.ndfi0id() if 'data' in d: maps.append({'data': d['data'], 'info': 'NDFI t0'}) d = ndfi.ndfi1id() if 'data' in d: maps.append({'data' :d['data'], 'info': 'NDFI t1'}) return maps
def xmlrpc_test_bulk_insert(self, count, same_crackers = False): if same_crackers and len(self._crackers) < count: logging.debug("Filling static crackers from {} to {}".format(len(self._crackers), count)) for i in xrange(len(self._crackers), count): self._crackers.append(self.random_ip_address()) for i in xrange(count): reporter = self.random_ip_address() if same_crackers: cracker_ip = self._crackers[i] else: cracker_ip = self.random_ip_address() logging.debug("Adding report for {} from {}".format(cracker_ip, reporter)) yield utils.wait_and_lock_host(cracker_ip) cracker = yield Cracker.find(where=['ip_address=?', cracker_ip], limit=1) if cracker is None: now = time.time() cracker = Cracker(ip_address=cracker_ip, first_time=now, latest_time=now, total_reports=0, current_reports=0) yield cracker.save() yield controllers.add_report_to_cracker(cracker, reporter) utils.unlock_host(cracker_ip) logging.debug("Done adding report for {} from {}".format(cracker_ip,reporter)) total = yield Cracker.count() total_reports = yield Report.count() returnValue((total,total_reports))
def default_maps(): maps = [] r = Report.current() logging.info("report " + unicode(r)) ee_resource = 'MOD09GA' landsat = EELandsat('LANDSAT/L7_L1T') ndfi = NDFI(ee_resource, past_month_range(r.start), r.range()) d = landsat.mapid(*r.range()) if 'data' in d: maps.append({'data' :d['data'], 'info': 'LANDSAT/L7_L1T'}) """ d = landsat.mapid(*past_month_range(r.start)) if 'data' in d: maps.append({'data' :d['data'], 'info': 'LANDSAT/L7_L1T-old'}) """ #d = ndfi.mapid2() #if 'data' in d: #maps.append({'data' :d['data'], 'info': 'ndfi difference'}) d = ndfi.smaid() if 'data' in d: maps.append({'data': d['data'], 'info': 'SMA'}) d = ndfi.rgbid() if 'data' in d: maps.append({'data': d['data'], 'info': 'RGB'}) d = ndfi.ndfi0id() if 'data' in d: maps.append({'data': d['data'], 'info': 'NDFI T0'}) d = ndfi.ndfi1id() if 'data' in d: maps.append({'data' :d['data'], 'info': 'NDFI T1'}) return maps
def save_reports(): ret = {"err": 0, "msg": "Report id is save"} getreport = Report.query.all() for report in getreport: print("fatching Report name . . .: ", report.boat_name) print("fatching Report boat type .: ", report.boat_type) print("fatching Report lat . . . : ", report.lat) print("fatching Report lng . . . .: ", report.lng) print("fatching Report user . . . : ", report.user) try: # boat_id = int(request.form['boat_id']) boat_name = request.form['boat_name'] boat_type = request.form['boat_type'] get_lat = request.form['get_lat'] get_lng = request.form['get_lng'] user_id = int(request.form['user_id']) # boatcheck = Boat.query.filter_by(id=boat_id).first() # if not boatcheck: # ret["err"] = 1 # ret["msg"] = "Boat is not exist" # else: # # saving report # report.boat = boat_id report = Report(boat_name, boat_type, get_lat, get_lng, user_id) db.session.add(report) db.session.commit() ret["report_id"] = report.id except Exception as exp: print("save_reports() :: Got exp: %s" % exp) print(traceback.format_exc()) return json.dumps(ret)
def add_report(request): """ Adds a report filled by a user to the site's reports record :param request: Request :return: HttpResponse """ if request.method == 'POST' and request.is_ajax: deq = request.POST.get('description') idq = request.POST.get('idq') quest = Question.objects.get(id=idq) report = Report(report_description=deq) report.question = quest report.save() return HttpResponse("OK") else: return HttpResponse("Something went wrong")
def stats(table, zone=None, format="csv"): reports = request.args.get('reports', None) if not reports: abort(400) try: reports = map(int, reports.split(',')) except ValueError: logging.error("bad format for report id") abort(400) this_report = ReportType.factory(format) this_report.init(zone) this_report.write_header() logging.info("table id is %s ", table) logging.info("and we see %s ", FustionTablesNames.all().filter('table_id =', table).fetch(1)) logging.info("and zone %s ", zone) logging.info("and format %s ", format) reports = [Report.get_by_id(x) for x in reports] for r in reports: if not r: logging.error("report not found") abort(404) stats = this_report.get_stats(r, table) for s in stats: this_report.write_row(r, s, table) this_report.write_footer() return this_report.response("report_%s" % table)
def default_maps(): maps = [] r = Report.current() logging.info("report " + unicode(r)) ee_resource = "MOD09GA" landsat = EELandsat("LANDSAT/L7_L1T") ndfi = NDFI(ee_resource, past_month_range(r.start), r.range()) d = landsat.mapid(*r.range()) if "data" in d: maps.append({"data": d["data"], "info": "LANDSAT/L7_L1T"}) """ d = landsat.mapid(*past_month_range(r.start)) if 'data' in d: maps.append({'data' :d['data'], 'info': 'LANDSAT/L7_L1T-old'}) """ # d = ndfi.mapid2() # if 'data' in d: # maps.append({'data' :d['data'], 'info': 'ndfi difference'}) d = ndfi.smaid() if "data" in d: maps.append({"data": d["data"], "info": "SMA"}) d = ndfi.rgbid() if "data" in d: maps.append({"data": d["data"], "info": "RGB"}) d = ndfi.ndfi0id() if "data" in d: maps.append({"data": d["data"], "info": "NDFI t0"}) d = ndfi.ndfi1id() if "data" in d: maps.append({"data": d["data"], "info": "NDFI t1"}) return maps
def report_get(self, request): item = Report.get_by_id(request.id) current_user = users.get_current_user() if item and item.author == current_user.author: return item.to_message() else: raise endpoints.NotFoundException('Report %s not found.' % (request.id,))
def report(request): if request.method == 'POST': errors = [] try: patientId = int(request.POST.get('patientId')) name = request.POST.get('name') latitude = float(request.POST.get('latitude')) longitude = float(request.POST.get('longitude')) dt = request.POST.get('datetime') datetime = datetime.strptime(dt,"%Y-%m-%d %H:%M:%S") incomingReport = Report(patientId=patientId, name=name, \ latitude=latitude, longitude=longitude, datetime=datetime) incomingReport.save() return HttpResponse("Report successfully added to database") except ValueError: return HttpResponse("Report not added properly") else: raise Http404
def imagepicker_tile(): if request.method == 'POST' and request.form.get('list_cloud_percent') and request.form.get('date_start') and request.form.get('date_end'): date_start = request.form.get('date_start') date_end = request.form.get('date_end') date_start = datetime.datetime.strptime(date_start,"%d/%b/%Y") date_end = datetime.datetime.strptime(date_end,"%d/%b/%Y") list_cloud_percent = request.form.get('list_cloud_percent') list_cloud_percent = json.loads(list_cloud_percent) landstat = EELandsat(date_start, date_end) result = landstat.get_thumbs(list_cloud_percent) return jsonify({'result': result}) elif request.method == 'POST' and request.form.get('thumbs_tile'): logging.info(request.form.get('thumbs_tile')) thumbs_tile = request.form.get('thumbs_tile') thumbs_tile = thumbs_tile.split(',') date_start = request.form.get('date_start') date_end = request.form.get('date_end') date_start = datetime.datetime.strptime(date_start,"%d/%b/%Y") date_end = datetime.datetime.strptime(date_end,"%d/%b/%Y") result = "" sensor_date = {} for i in range(len(thumbs_tile)): date, tile, sensor = thumbs_tile[i].split('__') if tile not in sensor_date.keys(): sensor_date[tile] = {} sensor_date[tile]['location'] = Tile.find_geo_region(tile.replace("_", "/")) sensor_date[tile]['sensor_date'] = [] sensor_date[tile]['sensor_date'].append(sensor+'__'+date) else: sensor_date[tile]['sensor_date'].append(sensor+'__'+date) report = Report.current() logging.info("===== sensor_date =====") logging.info(sensor_date) for key in sensor_date: imagePicker = ImagePicker(report=report, added_by= users.get_current_user(), cell=str(key.replace("_", "/")), location=str(sensor_date[key]['location']), sensor_dates=sensor_date[key]['sensor_date'], start=date_start, end=date_end) result = result + imagePicker.save() return jsonify({'result': result}) else: return jsonify({'result': None})
def range_report(): date_start = request.form.get('date_start') date_end = request.form.get('date_end') message = '' #try: message = Report.add_report(date_start, date_end) #except: # return jsonify({'result': 'error'}) return jsonify({'result': message})
def get_query(self): if request.args.get('method', '') == "listURI": # monkey patch fields self._fields = {self.model: ['latest', 'count', 'uri']} return Report.select(Report.uri, fn.Count(Report.id).alias( 'count'), fn.Max(Report.created).alias('latest')).group_by( Report.uri).order_by(fn.Max(Report.created).desc()) else: self._fields = {self.model: self.model._meta.get_field_names()} return SessionAuthResource.get_query(self)
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))
def cpanel_open(request): user = request.user device_choices = Device.get_device_choices(Device()) os_choices = Device.get_os_choices(Device()) problem_choices = Report.get_problem_choices(Report()) return render_to_response('cpanel/open.html', { 'user' : user, 'device_choices' : device_choices, 'os_choices' : os_choices, 'problem_choices' : problem_choices }, context_instance=RequestContext(request))
def post(self): user = users.get_current_user() if user: data = json.decode(self.request.body) # logging.log(logging.INFO, data) url = data['url'] if url[:3] != 'http': url = 'http://' + url report = Report( author=user, url=url, status='SENT' ) key = report.put() deferred.defer(parsepage, key, _countdown=30, _queue="parsequeue") result = { 'result': JSONEncoder().encode(key.get()), } self.response.headers['Content-Type'] = 'application/json' self.response.write(json.encode(result))
def set_data_for(self, on, end): reports = [] if end: # self.parent.current_period.setText(self.parent.format_period(on, # end)) reports = Report.filter(date__gte=date_on_or_end(on), date__lte=date_on_or_end(end, on=False)).order_by(Report.date.desc()) self.data = [(rap.product, rap.remaining, rap.selling_price, rap.remaining * rap.selling_price, rap.qty * (rap.selling_price - rap.selling_price)) for rap in reports]
def set_data_for(self): date = self.parent.date_.text() self.data = [(rap.product.name, formatted_number(rap.qty), formatted_number(rap.selling_price), rap.qty * rap.selling_price) for rap in Report.select().where( Report.type_ == Report.S, Report.date < date_on_or_end(date, on=False), Report.date > date_on_or_end(date) ).order_by(Report.id.desc())] self.refresh()
def picker(tile=None): if request.method == 'POST': logging.info(request.form.get('thumb')) cell = request.form.get('tile') p = re.compile('\d+') p = p.findall(cell) cell = 'h' + p[0] + 'v' + p[1] thumbs = request.form.get('thumb').split(',') sensor_dates = [] for i in range(len(thumbs)): day, month, year = thumbs[i].split('-') sensor_dates.append('modis__' + year +'-'+ month +'-'+ day) location = get_modis_location(cell) report = Report.current() date_start = datetime.datetime.combine(report.start, datetime.time()) date_end = datetime.datetime.combine(report.end, datetime.time()) imagePicker = ImagePicker(report=report, added_by= users.get_current_user(), cell=str(cell), location=location, sensor_dates=sensor_dates, start=date_start, end=date_end) return jsonify({'result': imagePicker.save()}) else: #cell = request.args.get('cell', '') reports = Report.current().as_dict() date = time.gmtime(reports['start'] / 1000) year = time.strftime("%Y", date) month = time.strftime("%m", date) if tile: bands = 'sur_refl_b01,sur_refl_b04,sur_refl_b03' gain = 0.1 results = get_modis_thumbnails_list(year, month, tile, bands, gain) return jsonify({'result': results}) else: return jsonify({'result': []})
def perform_maintenance(limit = None, legacy_limit = None): logging.info("Starting maintenance job...") if limit is None: now = time.time() limit = now - config.expiry_days * 24 * 3600 if legacy_limit is None: now = time.time() legacy_limit = now - config.legacy_expiry_days * 24 * 3600 reports_deleted = 0 crackers_deleted = 0 legacy_deleted = 0 batch_size = 1000 while True: old_reports = yield Report.find(where=["latest_report_time<?", limit], limit=batch_size) if len(old_reports) == 0: break logging.debug("Removing batch of {} old reports".format(len(old_reports))) for report in old_reports: cracker = yield report.cracker.get() yield utils.wait_and_lock_host(cracker.ip_address) try: logging.debug("Maintenance: removing report from {} for cracker {}".format(report.ip_address, cracker.ip_address)) yield report.cracker.clear() yield report.delete() reports_deleted += 1 current_reports = yield cracker.reports.get(group='ip_address') cracker.current_reports = len(current_reports) yield cracker.save() if cracker.current_reports == 0: logging.debug("Maintenance: removing cracker {}".format(cracker.ip_address)) yield cracker.delete() crackers_deleted += 1 finally: utils.unlock_host(cracker.ip_address) logging.debug("Maintenance on report from {} for cracker {} done".format(report.ip_address, cracker.ip_address)) legacy_reports = yield Legacy.find(where=["retrieved_time<?", legacy_limit]) if legacy_reports is not None: for legacy in legacy_reports: yield legacy.delete() legacy_deleted += 1 logging.info("Done maintenance job") logging.info("Expired {} reports and {} hosts, plus {} hosts from the legacy list".format(reports_deleted, crackers_deleted, legacy_deleted)) returnValue(0)
def vis(): u = get_or_create_user() if not u: abort(403) logout_url = users.create_logout_url('/') #TODO show only finished reports = [x.as_dict() for x in Report.all().filter("finished =", True).order("start")] return render_template('vis/index.html', user=u, logout_url=logout_url, polygons_table=settings.FT_TABLE_ID, reports=json.dumps(reports))