from tempfile import tempdir import firebase_admin from firebase_admin import credentials from firebase_admin import db from find_s1_image2 import find_img_value import pandas as pd import statsmodels.api as sm import seaborn as sns sns.set() import csv import time import traceback import json import numpy as np from sklearn.cluster import KMeans from find_study_area_values import find_study_area_values from make_area_estimate_image import make_area_estimate_image import json import xlsxwriter import datetime import requests from sentinelhub import WebFeatureService, BBox, CRS, MimeType, CRS, BBox, WmsRequest,DataCollection cred = credentials.Certificate('servicekey.json') x = 0.0003 y = 0.0003 fromdate = '20220701' todate = '20220715' s1_images = ['IW-VH-DB'] s2_images = [] # s1_images = ["B02", "B03", "B04", "B05"] #s2_images = ["RVI-NEW"] try: firebase_admin.initialize_app(cred, {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') workbook = xlsxwriter.Workbook('bhumitantra.xlsx') worksheet = workbook.add_worksheet() uids = ['AvlbNpsuI7P1sva1NWMBUN4Fmbg1','2Gpn5tspykcKPt0tQqkQrpT52Ji2', 'DgwGhWlZKndMe33MlmSnt2Vp0PD2', 'JNH5nfMdqDOQGrTOM0wrVysxgH92'] main_arr = [] row = 1 main_arr.append(['Name & Phone Number', 'Coordinates']) uids = ['fSRlyKzCxxMJHJqDzpGhQImyyxf2','rF4qo7DGoxd3AeEC1Ux4vBGbsbl1'] uids = ['M53J9SImW9My4vghlCaaWLYxsc22'] all_farmers = [] #uids = ['YkJIYa63SLhOZdmo4hRKZ17z4lq2'] #uids = ['3slpdq65yYXR6M9zDU2I3Ng6kRD2'] for uid in uids: all_fields = db.reference('PaidMonitoredFields').child('PMF').child(uid).get() try: for (fieldid, fieldobj) in all_fields.items(): #field_address = fieldobj["FieldAddress"] #points_obj = fieldobj["Coordinates"] # all_points = [] # for (pointKey, single_point) in points_obj.items(): # all_points.append([single_point["Latitude"], single_point["Longitude"]]) # print(field_address) # split_address = field_address.split(",") #db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Expired').delete() print(fieldid) db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Expiring').set('no') db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('PaymentType').set('4') db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Expired').delete() # db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Phone').set(split_address[1]) # all_farmers.append([split_address[0],split_address[1], all_points]) # temp_obj = {} # temp_obj["UID"] = "3slpdq65yYXR6M9zDU2I3Ng6kRD2" # temp_obj["Points"] = points_obj # print(temp_obj) # r = requests.post('https://us-central1-farmbase-b2f7e.cloudfunctions.net/getFieldAreaByBoundaryPoints', json = temp_obj) # print(r.text) # res_obj = json.loads(r.text) # area = res_obj["FieldArea"] # print(area) # db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('FieldArea').set(area) # #break #time.sleep(1) # sensed_days = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('SensedDays').get() # new_sensed_days = {} # len_days = 0 # for (p,q) in sensed_days.items(): # len_days = len_days+1 # temp_len = 0 # for (x,y) in sensed_days.items(): # if temp_len < len_days - 1: # new_sensed_days[x] = y # temp_len = temp_len+1 # print([sensed_days, new_sensed_days]) #db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('SensedDays').set(new_sensed_days) #db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Language').set('hi,en') time.sleep(0.1) # pointsObj = fieldobj["Coordinates"] # midlat, midlng, pointNum = 0,0,0 # for (point_key, point_obj) in pointsObj.items(): # lat = point_obj["Latitude"] # lng = point_obj["Longitude"] # midlat = midlat + lat # midlng = midlng + lng # pointNum = pointNum + 1 # midlat = midlat/pointNum # midlng = midlng/pointNum # field_address = fieldobj["FieldAddress"] # worksheet.write(row, 0, field_address) # worksheet.write(row, 1, (str(midlat) + ', ' + str(midlng))) # worksheet.write(row, 2, fieldid) # main_arr.append([field_address, (str(midlat) + ', ' + str(midlng))]) # row = row + 1 except: print(traceback.format_exc()) with open('itc_list', 'w') as f: # using csv.writer method from CSV package write = csv.writer(f) write.writerow(['Name', 'Phone Number', 'Boundary Points']) write.writerows(all_farmers)