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 pdf from sklearn.metrics import classification_report, confusion_matrix, accuracy_score import statsmodels.api as sm import seaborn as sns sns.set() import traceback from sklearn.ensemble import RandomForestRegressor from sklearn.model_selection import train_test_split import csv import time import json from find_modis_ndvi import find_modis_ndvi import numpy as np from sklearn.cluster import KMeans from sentinelhub import WebFeatureService, BBox, CRS, MimeType, CRS, BBox, WmsRequest,DataCollection import traceback from get_mask import get_mask from PIL import Image import numpy as np from google.cloud import storage import requests from simplify_coordinates import simplify_coordinates 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') uid = 'TCXcp5VIsfhHZrh0nm2VsgBtcGy2' uid = 'VKXzYbNY89YD7UePtUL5KbxLYTE3' uid2 = 'temp_ipRHhCOFIDV2pxgg7Nfz1ufZBmV2' num = 0 uid = 'qbnmIkSbAwc8TTR5FPnViu2Rr0A2' uid = 'HF9dSIoDEYcTwebrRWVzb08SQln2' main_num = 0 #test_uid = 'MtO6G7AvlnPgQxAajMP6NtLS8fN2' temp_list = db.reference('PaidMonitoredFields').child('PMF').child(uid).get(False, True) date_list = ['20230715', '20230720', '20230725', '20230730', '20230804', '20230809', '20230814', '20230819', '20230824', '20230829', '20230903', '20230908', '20230913', '20230918', '20230923', '20230928', '20231003', '20231008', '20231013', '20231018', '20231023', '20231028', '20231102', '20231107', '20231112', '20231117', '20231217', '20231222', '20231227', '20240101', '20240106', '20240111', '20240116', '20240121', '20240126', '20240131', '20240205', '20240210', '20240215', '20240220', '20240225', '20240301', '20240306', '20240311', '20240316', '20240321', '20240326', '20240331', '20240405', '20240410', '20240415'] date_obj = {} for single_date in date_list: date_obj[single_date] = 'yes' print(date_obj) main_num = 0 #8203;:citation[【oaicite:0】]​ #temp_list = db.reference('IFPRITemp').get() not_list = [] for field_id, field_obj in temp_list.items(): field_id = str(field_id) # main_num = main_num + 1 # done = 0 db.reference('PaidMonitoredFields').child('PMF').child(uid).child(field_id).child('Expired').delete() db.reference('PaidMonitoredFields').child('PMF').child(uid).child(field_id).child('PaymentType').set(12) print(field_id) # if sensed_obj is not None: # for key, val in sensed_obj.items(): # key = str(key) # done = 0 # if key.find('202404') > -1: # num = num + 1 # done = 1 # break # if done == 0: # not_list.append(field_id) # print(num, main_num) # print(not_list) # db.reference('PaidMonitoredFields').child('PMF').child(uid).child(field_id).child('PreviousDataRequests').set(date_obj) # print(field_id) # time.sleep(0.5) # temp_field_obj = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(field_id).get() # if temp_field_obj is None: # new_obj = db.reference('PaidMonitoredFields').child('PMF').child(uid2).child(field_id).get() # db.reference('PaidMonitoredFields').child('PMF').child(uid).child(field_id).set(new_obj) # print(field_id) # time.sleep(0.05) # main_num = main_num+1 # if temp_field_obj is None: # num = num + 1 # db.reference('PaidMonitoredFields').child('PMF').child(uid).child(field_id).set(field_obj) # time.sleep(0.1) # print(main_num, num) time.sleep(100000) uid_list = {} for rr, tt in temp_list.items(): #get all polygons in the field if int(rr) < 1715797800000: db.reference('PaidMonitoredFields').child('PMF').child(uid).child(rr).delete() print(rr) time.sleep(0.1) # polygons_obj = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(rr).child('Polygons').get(False, True) # try: # for polygon_id, uu in polygons_obj.items(): # polygon_id = str(polygon_id) # sensed_days_obj = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(rr).child('Polygons').child(polygon_id).child('SensedDays').get() # sensed_days_arr = [] # try: # for temp_key, val in sensed_days_obj.items(): # sensed_days_arr.append(int(temp_key)) # if len(sensed_days_arr) >0: # if max(sensed_days_arr) > 20240415: # main_num = main_num + 1 # print(main_num) # except: # print(traceback.format_exc()) # # main_num = main_num + 1 # # #check if the polygon exists in the polygons tree # # paid_polygon_id = db.reference('PaidPolygonsByPolygonID').child('PMF').child(uid).child(polygon_id).child('polygonID').get() # # #print((polygon_id,paid_polygon_id)) # # if paid_polygon_id is None: # # num = num+1 # # #print(num) # # actual_polygon_obj = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(rr).child('Polygons').child(polygon_id).get() # # db.reference('PaidPolygonsByPolygonID').child('PMF').child(uid).child(polygon_id).set(actual_polygon_obj) # except: # print(traceback.format_exc()) print((main_num, num))