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 from sentinelhub import WebFeatureService, BBox, CRS, DataSource, 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'] all_farmers = [] 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"] print(split_address) split_address = field_address.split(",","") all_farmers.append([split_address[0],split_address[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']) write.writerows(all_farmers)