コード例 #1
0
    def post(self):

        # Add a row to audit history table before inserting into fertilizer table

        sql = api_select_options.select_fertilizer_edits;
        # .format(self.fertilizer_name,self.taluka_code);
        params = {
        "fertilizer_name": self.fertilizer_name,
        "taluka_code": self.taluka_code
        }
        g = DatabaseConnection().select_table_detail(sql,params);
        print(g)

        self.input_list = [g[0][0], g[0][1], g[0][2],g[0][3],g[0][4],g[0][5],g[0][6],g[0][7],g[0][8],g[0][9],g[0][10],g[0][11]]
        print(self.input_list)
        audit_input_parm = tuple(self.input_list)
        print(audit_input_parm)
        sql = api_insert_options.insert_fertilizer_audit_tbl

        DatabaseConnection().insert_table_detail(sql,audit_input_parm)

        # Edit existing row in fertilizer_ref_tbl after adding detail into audit table

        self.cost_per_kg = self.bag_cost_INR / self.bag_weight_kg

        sql = api_update_options.update_fertilizer_ref_tbl
        self.input_list = []
        self.input_list = [self.cost_per_kg, self.bag_weight_kg, self.bag_cost_INR, self.n_per_bag_kg, self.p_per_bag_kg, self.k_per_bag_kg, self.user_id, self.activity, self.fertilizer_name, self.taluka_code]
        ref_input_parm = tuple(self.input_list)

        message = DatabaseConnection().update_table_detail(sql,ref_input_parm)

        return message
コード例 #2
0
    def post(self):

        # Add a row to audit history table before inserting into nutrient dtl table

        sql = api_select_options.select_nutrient_edits
        g = DatabaseConnection().select_table_detail(sql=sql,
                                                     params=self.params)
        self.input_list = [
            g[0][0], g[0][1], g[0][2], g[0][3], g[0][4], g[0][5], g[0][6],
            g[0][7], g[0][8], g[0][9]
        ]

        audit_input_parm = tuple(self.input_list)
        sql = api_insert_options.insert_nutrient_audit_tbl

        DatabaseConnection().insert_table_detail(sql, audit_input_parm)

        # Edit existing row in nutrient_ref_tbl after adding detail into audit table
        sql = api_update_options.update_nutrient_ref_tbl
        self.input_list = []
        self.input_list = [
            self.n_kg_per_acre, self.p_kg_per_acre, self.k_kg_per_acre,
            self.user_id, self.activity, self.crop_name,
            self.irrigation_type_code
        ]
        ref_input_parm = tuple(self.input_list)

        message = DatabaseConnection().update_table_detail(sql, ref_input_parm)

        return message
コード例 #3
0
    def get(self):
        # Fetch data from region_dtl_tbl
        sql = api_select_options.select_region_dtl_tbl
        g = DatabaseConnection().select_table_detail(sql=sql, params=None)

        # Convert tuple data from micronutrient_ref_tbl to JSON array micronutrient_dtl_json
        for i in range(len(g)):
            for j in range(4):
                if (j == 0):
                    self.region_json["taluka_code"] = g[i][j]
                if (j == 1):
                    self.region_json["state_name"] = g[i][j]
                if (j == 2):
                    self.region_json["district_name"] = g[i][j]
                if (j == 3):
                    self.region_json["taluka_name"] = g[i][j]
                j = j + 1

            self.temp_array.append(copy.deepcopy(self.region_json))
            i = i + 1

        region_dtl_json = {
            "region_dtl": copy.copy(self.temp_array)
        }

        return region_dtl_json
コード例 #4
0
    def get(self):
        # Fetch data from nutrient_ref_tbl
        sql = api_select_options.select_nutrient_ref_tbl;
        g = DatabaseConnection().select_table_detail(sql=sql,params=None);

        # Convert tuple data from nutrient_ref_tbl to JSON array nutrient_dtl_json
        for i in range(len(g)):
            for j in range(7):
                if (j == 0):
                    self.nutrient_json["crop_name"] = g[i][j];
                if (j == 1):
                    self.nutrient_json["irrigation_type_code"] = g[i][j];
                if (j == 2):
                    self.nutrient_json["n_kg_per_acre"] = g[i][j];
                if (j == 3):
                    self.nutrient_json["p_kg_per_acre"] = g[i][j];
                if (j == 4):
                    self.nutrient_json["k_kg_per_acre"] = g[i][j];
                if (j == 5):
                    self.nutrient_json["taluka_code"] = g[i][j];
                if (j == 6):
                    self.nutrient_json["taluka_name"] = g[i][j];
                j=j+1;

            self.temp_array.append(copy.deepcopy(self.nutrient_json));
            i=i+1;

        nutrient_dtl_json = {"nutrient": copy.copy(self.temp_array)};

        return nutrient_dtl_json
コード例 #5
0
    def get(self):
        # Fetch data from micronutrient_ref_tbl
        sql = api_dropdown_options.select_micronutrient_ref_tbl
        g = DatabaseConnection().select_table_detail(sql=sql)

        # Convert tuple data from micronutrient_ref_tbl to JSON array micronutrient_dtl_json
        for i in range(len(g)):
            for j in range(5):
                if (j == 0):
                    self.micronutrient_json["crop_name"] = g[i][0]
                if (j == 1):
                    self.micronutrient_json["irrigation_type_code"] = g[i][1]
                if (j == 2):
                    self.micronutrient_json["N_per_hectare"] = g[i][2]
                if (j == 3):
                    self.micronutrient_json["P_per_hectare"] = g[i][3]
                if (j == 4):
                    self.micronutrient_json["K_per_hectare"] = g[i][4]
                j = j + 1

            self.temp_array.append(copy.deepcopy(self.micronutrient_json))
            i = i + 1

        micronutrient_dtl_json = {
            "micronutrient": copy.copy(self.temp_array)
        }

        return micronutrient_dtl_json
コード例 #6
0
    def get(self):

        # Fetch data from micronutrient_ref_tbl
        sql = api_select_options.select_fertilizer_ref_tbl
        g = DatabaseConnection().select_table_detail(sql=sql, params=None)

        # Convert tuple data from fertilizer_ref_tbl to JSON array fertilizer_dtl_json
        for i in range(len(g)):
            for j in range(8):
                if (j == 0):
                    self.fertilizer_json["fertilizer_name"] = g[i][j]
                if (j == 1):
                    self.fertilizer_json["bag_weight_kg"] = g[i][j]
                if (j == 2):
                    self.fertilizer_json["bag_cost_INR"] = g[i][j]
                if (j == 3):
                    self.fertilizer_json["taluka_code"] = g[i][j]
                if (j == 4):
                    self.fertilizer_json["n_per_bag_kg"] = g[i][j]
                if (j == 5):
                    self.fertilizer_json["p_per_bag_kg"] = g[i][j]
                if (j == 6):
                    self.fertilizer_json["k_per_bag_kg"] = g[i][j]
                if (j == 7):
                    self.fertilizer_json["taluka_name"] = g[i][j]
                j = j + 1

            self.temp_array.append(copy.deepcopy(self.fertilizer_json))
            i = i + 1

        fertilizer_dtl_json = {"fertilizer": copy.copy(self.temp_array)}

        return fertilizer_dtl_json
    def post(self):

        # perform sort of fertilizer_name & bag_cost in ascending order to match the sql output as bag cost will come from UI and NPK quantities and fertilier name will come from DB
        self.temp_array = []

        self.fertilizer_bag_cost = [
            x for _, x in sorted(zip(self.input1, self.input2))
        ]
        self.fertilizer_name = sorted(self.input1)

        fertilizer_name_list = []

        sql = api_dropdown_options.select_fertilizer_ref_tbl_npk.format(
            str(tuple(self.fertilizer_name)))
        npk_output = DatabaseConnection().select_table_detail(sql)

        for i in range(len(npk_output)):
            for j in range(5):

                if (j == 0):
                    self.N_qty_per_bag.append(npk_output[i][0])

                if (j == 1):
                    self.P_qty_per_bag.append(npk_output[i][1])

                if (j == 2):
                    self.K_qty_per_bag.append(npk_output[i][2])
                if (j == 3):
                    fertilizer_name_list.append(npk_output[i][3])
                if (j == 4):
                    self.fertilizer_bag_weight.append(npk_output[i][4])
                j = j + 1

            i = i + 1

        order = len(self.fertilizer_name)

        fertilizer_bag_required = np.zeros(order)

        if self.opts == 'single':
            #Optimized result - Single solver
            optimized_output = single_solver.optimize_minimize(
                self.N_deficit, self.P_deficit, self.K_deficit,
                fertilizer_bag_required, self.fertilizer_bag_cost,
                self.fertilizer_name, self.N_qty_per_bag, self.P_qty_per_bag,
                self.K_qty_per_bag, self.fertilizer_bag_weight)
            final_output = {"optimized_output": optimized_output}
        else:
            #Optimized result - Seperate solver for N,P & K
            optimized_output = NPK_solver.optimize_minimize(
                self.N_deficit, self.P_deficit, self.K_deficit,
                fertilizer_bag_required, self.fertilizer_bag_cost,
                self.fertilizer_name, self.N_qty_per_bag, self.P_qty_per_bag,
                self.K_qty_per_bag, self.fertilizer_bag_weight)
            final_output = {"optimized_output": optimized_output}

        return final_output
コード例 #8
0
    def post(self):

        ts = time.time()
        self.fertilizer_ID = datetime.datetime.fromtimestamp(ts).strftime(
            '%Y-%m-%d %H:%M:%S')

        self.input_list = [
            self.crop_name, self.irrigation_type_code, self.variety,
            self.farmer_ID, self.area_acre, self.n_soil_test, self.p_soil_test,
            self.k_soil_test, self.taluka_code, self.n_deficit, self.p_deficit,
            self.k_deficit, self.estimated_cost, self.user_id,
            self.fertilizer_ID
        ]
        params = tuple(self.input_list)
        print(params)
        sql = api_insert_options.insert_transaction_tbl

        message = DatabaseConnection().insert_table_detail(sql, params)

        for i in range(0, len(self.fertilizer_name_list)):
            self.fertilizer_input_list = []
            self.fertilizer_input_list.append(self.fertilizer_ID)
            self.fertilizer_input_list.append(self.fertilizer_name_list[i])
            self.fertilizer_input_list.append(
                self.fertilizer_bag_weight_list[i])
            self.fertilizer_input_list.append(
                self.fertilizer_quantity_kg_list[i])
            self.fertilizer_input_list.append(
                self.fertilizer_bag_required_list[i])
            input_parm = tuple(self.fertilizer_input_list)

            sql = api_insert_options.insert_transaction_fertilizer_tbl
            message = DatabaseConnection().insert_table_detail(
                sql, self.fertilizer_input_list)

        return message
コード例 #9
0
    def post(self):

        # Fetch data from crop_variety_ref_tbl for a given crop
        sql = api_select_options.select_variety
        g = DatabaseConnection().select_table_detail(sql=sql,
                                                     params=self.params)

        # Convert tuple data from crop_variety_ref_tbl to list
        for i in range(len(g)):
            self.variety_list.append(g[i][0])
            i = i + 1

        self.variety_list.append('Local')
        self.variety_list.append('Others')

        return self.variety_list
コード例 #10
0
    def post(self):

        # Insert a new raitamitra into the raitamitra_dtl_tbl

        self.input_list = [
            self.raitamitra_email, self.raitamitra_name,
            self.raitamitra_father_name, self.raitamitra_farmer_ID,
            self.raitamitra_mobile_number, self.raitamitra_gram_panchayat_code,
            self.raitamitra_village_code, self.raitamitra_taluka_code
        ]

        input_parm = tuple(self.input_list)

        sql = api_insert_options.insert_raitamitra_dtl_tbl

        message = DatabaseConnection().insert_table_detail(sql, input_parm)

        return message
コード例 #11
0
    def post(self):

        # Insert a new fertilizer into the fertilizer_ref_tbl

        self.bag_cost = self.cost_per_kg * self.unit_in_kg;

        if (self.s_per_unit is None):
            self.s_per_unit = 0

        self.input_list = [self.fertilizer_name, self.cost_per_kg, self.unit_in_kg,self.bag_cost,
                            self.n_per_unit,self.p_per_unit,self.k_per_unit,self.s_per_unit]

        input_parm = tuple(self.input_list)

        sql = insert_fertilizer.insert_fertilizer_ref_tbl

        message = DatabaseConnection().insert_table_detail(sql,input_parm)

        return message
コード例 #12
0
    def post(self):

        self.temp_array = []

        fertilizer_name_list = []
        sql = api_select_options.select_fertilizer_npk
        params = tuple(self.fertilizer_name)

        npk_output = DatabaseConnection().select_table_detail(sql, (params, ))

        for i in range(len(npk_output)):
            for j in range(6):

                if (j == 0):
                    self.N_qty_per_bag.append(npk_output[i][j])
                if (j == 1):
                    self.P_qty_per_bag.append(npk_output[i][j])
                if (j == 2):
                    self.K_qty_per_bag.append(npk_output[i][j])
                if (j == 3):
                    fertilizer_name_list.append(npk_output[i][j])
                if (j == 4):
                    self.fertilizer_bag_weight.append(npk_output[i][j])
                if (j == 5):
                    self.fertilizer_bag_cost.append(npk_output[i][j])
                j = j + 1

            i = i + 1

        order = len(self.fertilizer_name)

        fertilizer_bag_required = np.zeros(order)
        optimized_output = linear.optimize_minimize(
            self.N_deficit, self.P_deficit, self.K_deficit,
            fertilizer_bag_required, self.fertilizer_bag_cost,
            fertilizer_name_list, self.N_qty_per_bag, self.P_qty_per_bag,
            self.K_qty_per_bag, self.fertilizer_bag_weight)
        final_output = {"optimized_output": optimized_output}

        return final_output
コード例 #13
0
    def get(self):
        # Fetch data from region_dtl_tbl
        sql = api_select_options.select_user_access
        g = DatabaseConnection().select_table_detail(sql=sql, params=None)

        # Convert tuple data from micronutrient_ref_tbl to JSON array micronutrient_dtl_json
        for i in range(len(g)):
            for j in range(2):
                if (j == 0):
                    self.user_access_json["email_ID"] = g[i][j]
                if (j == 1):
                    self.user_access_json["user_access"] = g[i][j]
                j = j + 1

            self.temp_array.append(copy.deepcopy(self.user_access_json))
            i = i + 1

        user_access_json = {
            "user_access": copy.copy(self.temp_array)
        }

        return user_access_json
コード例 #14
0
    def post(self):

        # Insert a new fertilizer into the fertilizer_ref_tbl
        ts = time.time()
        self.activity_timestamp = datetime.datetime.fromtimestamp(ts).strftime(
            '%Y-%m-%d %H:%M:%S')

        self.cost_per_kg = self.bag_cost_INR / self.bag_weight_kg

        self.input_list = [
            self.fertilizer_name, self.cost_per_kg, self.bag_weight_kg,
            self.bag_cost_INR, self.n_per_bag_kg, self.p_per_bag_kg,
            self.k_per_bag_kg, self.taluka_code, self.user_id, self.activity,
            self.activity_timestamp
        ]

        input_parm = tuple(self.input_list)

        sql = api_insert_options.insert_fertilizer_ref_tbl

        message = DatabaseConnection().insert_table_detail(sql, input_parm)

        return message
コード例 #15
0
    def get(self):
        # Fetch data from micronutrient_ref_tbl
        sql = api_dropdown_options.select_fertilizer_ref_tbl;
        g = DatabaseConnection().select_table_detail(sql=sql);

        # Convert tuple data from fertilizer_ref_tbl to JSON array fertilizer_dtl_json
        for i in range(len(g)):
            for j in range(4):
                if (j == 0):
                    self.fertilizer_json["fertilizer_name"] = g[i][0]
                # if (j == 1):
                #     self.fertilizer_json["cost_per_kg"] = g[i][1]
                if (j == 2):
                    self.fertilizer_json["unit_in_kg"] = g[i][2]
                if (j == 3):
                    self.fertilizer_json["bag_cost"] = g[i][3]
                j=j+1;

            self.temp_array.append(copy.deepcopy(self.fertilizer_json))
            i=i+1;

        fertilizer_dtl_json = {"fertilizer": copy.copy(self.temp_array)}
        return fertilizer_dtl_json
コード例 #16
0
    def post(self):

        # Fetch data from micronutrient_ref_tbl
        sql = api_select_options.select_fertilizer.format(self.taluka_code);
        g = DatabaseConnection().select_table_detail(sql=sql,params=self.params);

        # Convert tuple data from fertilizer_ref_tbl to JSON array fertilizer_dtl_json
        for i in range(len(g)):
            for j in range(3):
                if (j == 0):
                    self.fertilizer_json["fertilizer_name"] = g[i][j]
                if (j == 1):
                    self.fertilizer_json["bag_weight_kg"] = g[i][j]
                if (j == 2):
                    self.fertilizer_json["bag_cost_INR"] = g[i][j]
                j=j+1;

            self.temp_array.append(copy.deepcopy(self.fertilizer_json))
            i=i+1;

        fertilizer_dtl_json = {"fertilizer": copy.copy(self.temp_array)}

        return fertilizer_dtl_json