| @@ 3739-3878 (lines=140) @@ | ||
| 3736 | " (combined_equipment_id, virtual_meter_id, is_output ) " |
|
| 3737 | " VALUES (%s, %s, %s) ") |
|
| 3738 | cursor.execute(add_row, (new_id, virtual_meter['id'], virtual_meter['is_output'])) |
|
| 3739 | if meta_result['parameters'] is not None and len(meta_result['parameters']) > 0: |
|
| 3740 | for parameters in meta_result['parameters']: |
|
| 3741 | cursor.execute(" SELECT name " |
|
| 3742 | " FROM tbl_combined_equipments_parameters " |
|
| 3743 | " WHERE name = %s AND combined_equipment_id = %s ", (parameters['name'], new_id)) |
|
| 3744 | if cursor.fetchone() is not None: |
|
| 3745 | cursor.close() |
|
| 3746 | cnx.close() |
|
| 3747 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3748 | description='API.COMBINED_EQUIPMENT_PARAMETER_NAME_IS_ALREADY_IN_USE') |
|
| 3749 | if 'point' in parameters: |
|
| 3750 | if parameters['point'] is None: |
|
| 3751 | point_id = None |
|
| 3752 | elif parameters['point']['id'] is not None and \ |
|
| 3753 | parameters['point']['id'] <= 0: |
|
| 3754 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3755 | description='API.INVALID_POINT_ID') |
|
| 3756 | else: |
|
| 3757 | point_id = parameters['point']['id'] |
|
| 3758 | else: |
|
| 3759 | point_id = None |
|
| 3760 | numerator_meter_uuid = None |
|
| 3761 | if 'numerator_meter' in parameters: |
|
| 3762 | if parameters['numerator_meter'] is not None and \ |
|
| 3763 | isinstance(parameters['numerator_meter']['uuid'], str) and \ |
|
| 3764 | len(str.strip(parameters['numerator_meter']['uuid'])) > 0: |
|
| 3765 | numerator_meter_uuid = str.strip(parameters['numerator_meter']['uuid']) |
|
| 3766 | ||
| 3767 | denominator_meter_uuid = None |
|
| 3768 | if 'denominator_meter' in parameters: |
|
| 3769 | if parameters['denominator_meter'] is not None and \ |
|
| 3770 | isinstance(parameters['denominator_meter']['uuid'], str) and \ |
|
| 3771 | len(str.strip(parameters['denominator_meter']['uuid'])) > 0: |
|
| 3772 | denominator_meter_uuid = str.strip(parameters['denominator_meter']['uuid']) |
|
| 3773 | ||
| 3774 | # validate by parameter type |
|
| 3775 | if parameters['parameter_type'] == 'point': |
|
| 3776 | if point_id is None: |
|
| 3777 | cursor.close() |
|
| 3778 | cnx.close() |
|
| 3779 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3780 | description='API.INVALID_POINT_ID') |
|
| 3781 | ||
| 3782 | query = (" SELECT id, name " |
|
| 3783 | " FROM tbl_points " |
|
| 3784 | " WHERE id = %s ") |
|
| 3785 | cursor.execute(query, (point_id,)) |
|
| 3786 | if cursor.fetchone() is None: |
|
| 3787 | cursor.close() |
|
| 3788 | cnx.close() |
|
| 3789 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3790 | description='API.POINT_NOT_FOUND') |
|
| 3791 | ||
| 3792 | elif parameters['parameter_type'] == 'constant': |
|
| 3793 | if parameters['constant'] is None: |
|
| 3794 | cursor.close() |
|
| 3795 | cnx.close() |
|
| 3796 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3797 | description='API.INVALID_CONSTANT_VALUE') |
|
| 3798 | ||
| 3799 | elif parameters['parameter_type'] == 'fraction': |
|
| 3800 | ||
| 3801 | query = (" SELECT id, name, uuid " |
|
| 3802 | " FROM tbl_meters ") |
|
| 3803 | cursor.execute(query) |
|
| 3804 | rows_meters = cursor.fetchall() |
|
| 3805 | ||
| 3806 | meter_dict = dict() |
|
| 3807 | if rows_meters is not None and len(rows_meters) > 0: |
|
| 3808 | for row in rows_meters: |
|
| 3809 | meter_dict[row[2]] = {"type": 'meter', |
|
| 3810 | "id": row[0], |
|
| 3811 | "name": row[1], |
|
| 3812 | "uuid": row[2]} |
|
| 3813 | ||
| 3814 | query = (" SELECT id, name, uuid " |
|
| 3815 | " FROM tbl_offline_meters ") |
|
| 3816 | cursor.execute(query) |
|
| 3817 | rows_offline_meters = cursor.fetchall() |
|
| 3818 | ||
| 3819 | offline_meter_dict = dict() |
|
| 3820 | if rows_offline_meters is not None and len(rows_offline_meters) > 0: |
|
| 3821 | for row in rows_offline_meters: |
|
| 3822 | offline_meter_dict[row[2]] = {"type": 'offline_meter', |
|
| 3823 | "id": row[0], |
|
| 3824 | "name": row[1], |
|
| 3825 | "uuid": row[2]} |
|
| 3826 | ||
| 3827 | query = (" SELECT id, name, uuid " |
|
| 3828 | " FROM tbl_virtual_meters ") |
|
| 3829 | cursor.execute(query) |
|
| 3830 | rows_virtual_meters = cursor.fetchall() |
|
| 3831 | ||
| 3832 | virtual_meter_dict = dict() |
|
| 3833 | if rows_virtual_meters is not None and len(rows_virtual_meters) > 0: |
|
| 3834 | for row in rows_virtual_meters: |
|
| 3835 | virtual_meter_dict[row[2]] = {"type": 'virtual_meter', |
|
| 3836 | "id": row[0], |
|
| 3837 | "name": row[1], |
|
| 3838 | "uuid": row[2]} |
|
| 3839 | ||
| 3840 | # validate numerator meter uuid |
|
| 3841 | if meter_dict.get(numerator_meter_uuid) is None and \ |
|
| 3842 | virtual_meter_dict.get(numerator_meter_uuid) is None and \ |
|
| 3843 | offline_meter_dict.get(numerator_meter_uuid) is None: |
|
| 3844 | cursor.close() |
|
| 3845 | cnx.close() |
|
| 3846 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3847 | description='API.INVALID_NUMERATOR_METER_UUID') |
|
| 3848 | ||
| 3849 | # validate denominator meter uuid |
|
| 3850 | if denominator_meter_uuid is None: |
|
| 3851 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3852 | description='API.INVALID_DENOMINATOR_METER_UUID') |
|
| 3853 | ||
| 3854 | if denominator_meter_uuid == numerator_meter_uuid: |
|
| 3855 | cursor.close() |
|
| 3856 | cnx.close() |
|
| 3857 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3858 | description='API.INVALID_DENOMINATOR_METER_UUID') |
|
| 3859 | ||
| 3860 | if denominator_meter_uuid not in meter_dict and \ |
|
| 3861 | denominator_meter_uuid not in virtual_meter_dict and \ |
|
| 3862 | denominator_meter_uuid not in offline_meter_dict: |
|
| 3863 | cursor.close() |
|
| 3864 | cnx.close() |
|
| 3865 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3866 | description='API.INVALID_DENOMINATOR_METER_UUID') |
|
| 3867 | ||
| 3868 | add_values = (" INSERT INTO tbl_combined_equipments_parameters " |
|
| 3869 | " (combined_equipment_id, name, parameter_type, constant, " |
|
| 3870 | " point_id, numerator_meter_uuid, denominator_meter_uuid) " |
|
| 3871 | " VALUES (%s, %s, %s, %s, %s, %s, %s) ") |
|
| 3872 | cursor.execute(add_values, (new_id, |
|
| 3873 | parameters['name'], |
|
| 3874 | parameters['parameter_type'], |
|
| 3875 | parameters['constant'], |
|
| 3876 | point_id, |
|
| 3877 | numerator_meter_uuid, |
|
| 3878 | denominator_meter_uuid)) |
|
| 3879 | cnx.commit() |
|
| 3880 | cursor.close() |
|
| 3881 | cnx.close() |
|
| @@ 3176-3315 (lines=140) @@ | ||
| 3173 | " (combined_equipment_id, virtual_meter_id, is_output ) " |
|
| 3174 | " VALUES (%s, %s, %s) ") |
|
| 3175 | cursor.execute(add_row, (new_id, virtual_meter['id'], virtual_meter['is_output'])) |
|
| 3176 | if new_values['parameters'] is not None and len(new_values['parameters']) > 0: |
|
| 3177 | for parameters in new_values['parameters']: |
|
| 3178 | cursor.execute(" SELECT name " |
|
| 3179 | " FROM tbl_combined_equipments_parameters " |
|
| 3180 | " WHERE name = %s AND combined_equipment_id = %s ", (parameters['name'], new_id)) |
|
| 3181 | if cursor.fetchone() is not None: |
|
| 3182 | cursor.close() |
|
| 3183 | cnx.close() |
|
| 3184 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3185 | description='API.COMBINED_EQUIPMENT_PARAMETER_NAME_IS_ALREADY_IN_USE') |
|
| 3186 | if 'point' in parameters: |
|
| 3187 | if parameters['point'] is None: |
|
| 3188 | point_id = None |
|
| 3189 | elif parameters['point']['id'] is not None and \ |
|
| 3190 | parameters['point']['id'] <= 0: |
|
| 3191 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3192 | description='API.INVALID_POINT_ID') |
|
| 3193 | else: |
|
| 3194 | point_id = parameters['point']['id'] |
|
| 3195 | else: |
|
| 3196 | point_id = None |
|
| 3197 | numerator_meter_uuid = None |
|
| 3198 | if 'numerator_meter' in parameters: |
|
| 3199 | if parameters['numerator_meter'] is not None and \ |
|
| 3200 | isinstance(parameters['numerator_meter']['uuid'], str) and \ |
|
| 3201 | len(str.strip(parameters['numerator_meter']['uuid'])) > 0: |
|
| 3202 | numerator_meter_uuid = str.strip(parameters['numerator_meter']['uuid']) |
|
| 3203 | ||
| 3204 | denominator_meter_uuid = None |
|
| 3205 | if 'denominator_meter' in parameters: |
|
| 3206 | if parameters['denominator_meter'] is not None and \ |
|
| 3207 | isinstance(parameters['denominator_meter']['uuid'], str) and \ |
|
| 3208 | len(str.strip(parameters['denominator_meter']['uuid'])) > 0: |
|
| 3209 | denominator_meter_uuid = str.strip(parameters['denominator_meter']['uuid']) |
|
| 3210 | ||
| 3211 | # validate by parameter type |
|
| 3212 | if parameters['parameter_type'] == 'point': |
|
| 3213 | if point_id is None: |
|
| 3214 | cursor.close() |
|
| 3215 | cnx.close() |
|
| 3216 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3217 | description='API.INVALID_POINT_ID') |
|
| 3218 | ||
| 3219 | query = (" SELECT id, name " |
|
| 3220 | " FROM tbl_points " |
|
| 3221 | " WHERE id = %s ") |
|
| 3222 | cursor.execute(query, (point_id,)) |
|
| 3223 | if cursor.fetchone() is None: |
|
| 3224 | cursor.close() |
|
| 3225 | cnx.close() |
|
| 3226 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3227 | description='API.POINT_NOT_FOUND') |
|
| 3228 | ||
| 3229 | elif parameters['parameter_type'] == 'constant': |
|
| 3230 | if parameters['constant'] is None: |
|
| 3231 | cursor.close() |
|
| 3232 | cnx.close() |
|
| 3233 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3234 | description='API.INVALID_CONSTANT_VALUE') |
|
| 3235 | ||
| 3236 | elif parameters['parameter_type'] == 'fraction': |
|
| 3237 | ||
| 3238 | query = (" SELECT id, name, uuid " |
|
| 3239 | " FROM tbl_meters ") |
|
| 3240 | cursor.execute(query) |
|
| 3241 | rows_meters = cursor.fetchall() |
|
| 3242 | ||
| 3243 | meter_dict = dict() |
|
| 3244 | if rows_meters is not None and len(rows_meters) > 0: |
|
| 3245 | for row in rows_meters: |
|
| 3246 | meter_dict[row[2]] = {"type": 'meter', |
|
| 3247 | "id": row[0], |
|
| 3248 | "name": row[1], |
|
| 3249 | "uuid": row[2]} |
|
| 3250 | ||
| 3251 | query = (" SELECT id, name, uuid " |
|
| 3252 | " FROM tbl_offline_meters ") |
|
| 3253 | cursor.execute(query) |
|
| 3254 | rows_offline_meters = cursor.fetchall() |
|
| 3255 | ||
| 3256 | offline_meter_dict = dict() |
|
| 3257 | if rows_offline_meters is not None and len(rows_offline_meters) > 0: |
|
| 3258 | for row in rows_offline_meters: |
|
| 3259 | offline_meter_dict[row[2]] = {"type": 'offline_meter', |
|
| 3260 | "id": row[0], |
|
| 3261 | "name": row[1], |
|
| 3262 | "uuid": row[2]} |
|
| 3263 | ||
| 3264 | query = (" SELECT id, name, uuid " |
|
| 3265 | " FROM tbl_virtual_meters ") |
|
| 3266 | cursor.execute(query) |
|
| 3267 | rows_virtual_meters = cursor.fetchall() |
|
| 3268 | ||
| 3269 | virtual_meter_dict = dict() |
|
| 3270 | if rows_virtual_meters is not None and len(rows_virtual_meters) > 0: |
|
| 3271 | for row in rows_virtual_meters: |
|
| 3272 | virtual_meter_dict[row[2]] = {"type": 'virtual_meter', |
|
| 3273 | "id": row[0], |
|
| 3274 | "name": row[1], |
|
| 3275 | "uuid": row[2]} |
|
| 3276 | ||
| 3277 | # validate numerator meter uuid |
|
| 3278 | if meter_dict.get(numerator_meter_uuid) is None and \ |
|
| 3279 | virtual_meter_dict.get(numerator_meter_uuid) is None and \ |
|
| 3280 | offline_meter_dict.get(numerator_meter_uuid) is None: |
|
| 3281 | cursor.close() |
|
| 3282 | cnx.close() |
|
| 3283 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3284 | description='API.INVALID_NUMERATOR_METER_UUID') |
|
| 3285 | ||
| 3286 | # validate denominator meter uuid |
|
| 3287 | if denominator_meter_uuid is None: |
|
| 3288 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3289 | description='API.INVALID_DENOMINATOR_METER_UUID') |
|
| 3290 | ||
| 3291 | if denominator_meter_uuid == numerator_meter_uuid: |
|
| 3292 | cursor.close() |
|
| 3293 | cnx.close() |
|
| 3294 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3295 | description='API.INVALID_DENOMINATOR_METER_UUID') |
|
| 3296 | ||
| 3297 | if denominator_meter_uuid not in meter_dict and \ |
|
| 3298 | denominator_meter_uuid not in virtual_meter_dict and \ |
|
| 3299 | denominator_meter_uuid not in offline_meter_dict: |
|
| 3300 | cursor.close() |
|
| 3301 | cnx.close() |
|
| 3302 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3303 | description='API.INVALID_DENOMINATOR_METER_UUID') |
|
| 3304 | ||
| 3305 | add_values = (" INSERT INTO tbl_combined_equipments_parameters " |
|
| 3306 | " (combined_equipment_id, name, parameter_type, constant, " |
|
| 3307 | " point_id, numerator_meter_uuid, denominator_meter_uuid) " |
|
| 3308 | " VALUES (%s, %s, %s, %s, %s, %s, %s) ") |
|
| 3309 | cursor.execute(add_values, (new_id, |
|
| 3310 | parameters['name'], |
|
| 3311 | parameters['parameter_type'], |
|
| 3312 | parameters['constant'], |
|
| 3313 | point_id, |
|
| 3314 | numerator_meter_uuid, |
|
| 3315 | denominator_meter_uuid)) |
|
| 3316 | cnx.commit() |
|
| 3317 | cursor.close() |
|
| 3318 | cnx.close() |
|
| @@ 3114-3240 (lines=127) @@ | ||
| 3111 | " INSERT INTO tbl_equipments_virtual_meters (equipment_id, virtual_meter_id, is_output ) " |
|
| 3112 | " VALUES (%s, %s, %s) ") |
|
| 3113 | cursor.execute(add_row, (new_id, virtual_meter['id'], virtual_meter['is_output'])) |
|
| 3114 | if meta_result['parameters'] is not None and len(meta_result['parameters']) > 0: |
|
| 3115 | for parameters in meta_result['parameters']: |
|
| 3116 | cursor.execute(" SELECT name " |
|
| 3117 | " FROM tbl_equipments_parameters " |
|
| 3118 | " WHERE name = %s AND equipment_id = %s ", (parameters['name'], new_id)) |
|
| 3119 | if cursor.fetchone() is not None: |
|
| 3120 | cursor.close() |
|
| 3121 | cnx.close() |
|
| 3122 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3123 | description='API.EQUIPMENT_PARAMETER_NAME_IS_ALREADY_IN_USE') |
|
| 3124 | if 'point' in parameters: |
|
| 3125 | if parameters['point'] is None: |
|
| 3126 | point_id = None |
|
| 3127 | elif parameters['point']['id'] is not None and \ |
|
| 3128 | parameters['point']['id'] <= 0: |
|
| 3129 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3130 | description='API.INVALID_POINT_ID') |
|
| 3131 | else: |
|
| 3132 | point_id = parameters['point']['id'] |
|
| 3133 | else: |
|
| 3134 | point_id = None |
|
| 3135 | numerator_meter_uuid = None |
|
| 3136 | if 'numerator_meter' in parameters: |
|
| 3137 | if parameters['numerator_meter'] is not None and \ |
|
| 3138 | isinstance(parameters['numerator_meter']['uuid'], str) and \ |
|
| 3139 | len(str.strip(parameters['numerator_meter']['uuid'])) > 0: |
|
| 3140 | numerator_meter_uuid = str.strip(parameters['numerator_meter']['uuid']) |
|
| 3141 | ||
| 3142 | denominator_meter_uuid = None |
|
| 3143 | if 'denominator_meter' in parameters: |
|
| 3144 | if parameters['denominator_meter'] is not None and \ |
|
| 3145 | isinstance(parameters['denominator_meter']['uuid'], str) and \ |
|
| 3146 | len(str.strip(parameters['denominator_meter']['uuid'])) > 0: |
|
| 3147 | denominator_meter_uuid = str.strip(parameters['denominator_meter']['uuid']) |
|
| 3148 | ||
| 3149 | # validate by parameter type |
|
| 3150 | if parameters['parameter_type'] == 'point': |
|
| 3151 | if point_id is None: |
|
| 3152 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3153 | description='API.INVALID_POINT_ID') |
|
| 3154 | query = (" SELECT id, name " |
|
| 3155 | " FROM tbl_points " |
|
| 3156 | " WHERE id = %s ") |
|
| 3157 | cursor.execute(query, (point_id,)) |
|
| 3158 | if cursor.fetchone() is None: |
|
| 3159 | cursor.close() |
|
| 3160 | cnx.close() |
|
| 3161 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3162 | description='API.POINT_NOT_FOUND') |
|
| 3163 | ||
| 3164 | elif parameters['parameter_type'] == 'constant': |
|
| 3165 | if parameters['constant'] is None: |
|
| 3166 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3167 | description='API.INVALID_CONSTANT_VALUE') |
|
| 3168 | ||
| 3169 | elif parameters['parameter_type'] == 'fraction': |
|
| 3170 | query = (" SELECT id, name, uuid " |
|
| 3171 | " FROM tbl_meters ") |
|
| 3172 | cursor.execute(query) |
|
| 3173 | rows_meters = cursor.fetchall() |
|
| 3174 | meter_dict = dict() |
|
| 3175 | if rows_meters is not None and len(rows_meters) > 0: |
|
| 3176 | for row in rows_meters: |
|
| 3177 | meter_dict[row[2]] = {"type": 'meter', |
|
| 3178 | "id": row[0], |
|
| 3179 | "name": row[1], |
|
| 3180 | "uuid": row[2]} |
|
| 3181 | ||
| 3182 | query = (" SELECT id, name, uuid " |
|
| 3183 | " FROM tbl_offline_meters ") |
|
| 3184 | cursor.execute(query) |
|
| 3185 | rows_offline_meters = cursor.fetchall() |
|
| 3186 | ||
| 3187 | offline_meter_dict = dict() |
|
| 3188 | if rows_offline_meters is not None and len(rows_offline_meters) > 0: |
|
| 3189 | for row in rows_offline_meters: |
|
| 3190 | offline_meter_dict[row[2]] = {"type": 'offline_meter', |
|
| 3191 | "id": row[0], |
|
| 3192 | "name": row[1], |
|
| 3193 | "uuid": row[2]} |
|
| 3194 | ||
| 3195 | query = (" SELECT id, name, uuid " |
|
| 3196 | " FROM tbl_virtual_meters ") |
|
| 3197 | cursor.execute(query) |
|
| 3198 | rows_virtual_meters = cursor.fetchall() |
|
| 3199 | ||
| 3200 | virtual_meter_dict = dict() |
|
| 3201 | if rows_virtual_meters is not None and len(rows_virtual_meters) > 0: |
|
| 3202 | for row in rows_virtual_meters: |
|
| 3203 | virtual_meter_dict[row[2]] = {"type": 'virtual_meter', |
|
| 3204 | "id": row[0], |
|
| 3205 | "name": row[1], |
|
| 3206 | "uuid": row[2]} |
|
| 3207 | ||
| 3208 | # validate numerator meter uuid |
|
| 3209 | if numerator_meter_uuid is None: |
|
| 3210 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3211 | description='API.INVALID_NUMERATOR_METER_UUID') |
|
| 3212 | ||
| 3213 | if meter_dict.get(numerator_meter_uuid) is None and \ |
|
| 3214 | virtual_meter_dict.get(numerator_meter_uuid) is None and \ |
|
| 3215 | offline_meter_dict.get(numerator_meter_uuid) is None: |
|
| 3216 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3217 | description='API.INVALID_NUMERATOR_METER_UUID') |
|
| 3218 | ||
| 3219 | # validate denominator meter uuid |
|
| 3220 | if denominator_meter_uuid == numerator_meter_uuid: |
|
| 3221 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3222 | description='API.INVALID_DENOMINATOR_METER_UUID') |
|
| 3223 | ||
| 3224 | if denominator_meter_uuid not in meter_dict and \ |
|
| 3225 | denominator_meter_uuid not in virtual_meter_dict and \ |
|
| 3226 | denominator_meter_uuid not in offline_meter_dict: |
|
| 3227 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3228 | description='API.INVALID_DENOMINATOR_METER_UUID') |
|
| 3229 | ||
| 3230 | add_values = (" INSERT INTO tbl_equipments_parameters " |
|
| 3231 | " (equipment_id, name, parameter_type, constant, " |
|
| 3232 | " point_id, numerator_meter_uuid, denominator_meter_uuid) " |
|
| 3233 | " VALUES (%s, %s, %s, %s, %s, %s, %s) ") |
|
| 3234 | cursor.execute(add_values, (new_id, |
|
| 3235 | parameters['name'], |
|
| 3236 | parameters['parameter_type'], |
|
| 3237 | parameters['constant'], |
|
| 3238 | point_id, |
|
| 3239 | numerator_meter_uuid, |
|
| 3240 | denominator_meter_uuid)) |
|
| 3241 | cnx.commit() |
|
| 3242 | cursor.close() |
|
| 3243 | cnx.close() |
|