9.sql 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <<<<<<< Updated upstream
  2. =======
  3. do $$
  4. begin
  5. >>>>>>> Stashed changes
  6. create sequence if not exists calc_header_adjustment_seq;
  7. create table if not exists calc_header_adjustment
  8. (
  9. id integer not null primary key default nextval('public.calc_header_adjustment_seq'),
  10. measurment_type_id integer not null,
  11. header varchar(100) not null,
  12. description text not null,
  13. values integer[] not null
  14. );
  15. create unique index ix_calc_header_adjustment_header_type on calc_header_adjustment(measurment_type_id, header);
  16. insert into calc_header_adjustment(measurment_type_id, header, description, values)
  17. values (1, 'table2', 'Заголовок для Таблицы № 2 (ДМК)', array[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50]),
  18. (2, 'table2','Заголовок для Таблицы № 2 (ВР)', array[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50]),
  19. (2, 'table3', 'Заголовок для Таблицы № 3 (ВР)', array[40,50,60,70,80,90,100,110,120,130,140,150]);
  20. create sequence if not exists calc_height_adjustment_seq;
  21. create table if not exists calc_height_adjustment
  22. (
  23. id integer primary key not null default nextval('public.calc_height_adjustment_seq'),
  24. height integer not null,
  25. measurment_type_id integer not null
  26. <<<<<<< Updated upstream
  27. );insert into calc_height_adjustment(height, measurment_type_id)
  28. =======
  29. );
  30. insert into calc_height_adjustment(height, measurment_type_id)
  31. >>>>>>> Stashed changes
  32. values(200,1),(400,1),(800,1),(1200,1),(1600,1),(2000,1),(2400,1),(3000,1),(4000,1),
  33. (200,2),(400,2),(800,2),(1200,2),(1600,2),(2000,2),(2400,2),(3000,2),(4000,2);
  34. create sequence if not exists calc_temperature_height_adjustment_seq;
  35. create table if not exists calc_temperature_height_adjustment
  36. (
  37. id integer primary key not null default nextval('public.calc_temperature_height_adjustment_seq'),
  38. calc_height_id integer not null,
  39. calc_temperature_header_id integer not null,
  40. positive_values numeric[],
  41. negative_values numeric[]
  42. );
  43. insert into calc_temperature_height_adjustment(calc_height_id, calc_temperature_header_id, positive_values, negative_values)
  44. values
  45. (10,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[ -1, -2, -3, -4, -5, -6, -7, -8, -8, -9, -20, -29, -39, -49]),
  46. (11,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -3, -4, -5, -6, -6, -7, -8, -9, -19, -29, -38, -48]),
  47. (12,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -3, -4, -5, -6, -6, -7, -7, -8, -18, -28, -37, -46]),
  48. (13,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -3, -4, -4, -5, -5, -6, -7, -8, -17, -26, -35, -44]),
  49. (14,1,array[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -3, -3, -4, -4, -5, -6, -7, -7, -17, -25, -34, -42]),
  50. (15,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -3, -3, -4, -4, -5, -6, -6, -7, -16, -24, -32, -40]),
  51. (16,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -2, -3, -4, -4, -5, -5, -6, -7, -15, -23, -31, -38]),
  52. (17,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -2, -3, -4, -4, -4, -5, -5, -6, -15, -22, -30, -37]),
  53. (18,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[ -1, -2, -2, -3, -4, -4, -4, -4, -5, -6, -14, -20, -27, -34]);
  54. insert into calc_temperature_height_adjustment(calc_height_id, calc_temperature_header_id, positive_values, negative_values)
  55. values
  56. (1,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[ -1, -2, -3, -4, -5, -6, -7, -8, -8, -9, -20, -29, -39, -49]),
  57. (2,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -3, -4, -5, -6, -6, -7, -8, -9, -19, -29, -38, -48]),
  58. (3,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -3, -4, -5, -6, -6, -7, -7, -8, -18, -28, -37, -46]),
  59. (4,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -3, -4, -4, -5, -5, -6, -7, -8, -17, -26, -35, -44]),
  60. (5,1,array[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -3, -3, -4, -4, -5, -6, -7, -7, -17, -25, -34, -42]),
  61. (6,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -3, -3, -4, -4, -5, -6, -6, -7, -16, -24, -32, -40]),
  62. (7,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -2, -3, -4, -4, -5, -5, -6, -7, -15, -23, -31, -38]),
  63. (8,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[-1, -2, -2, -3, -4, -4, -4, -5, -5, -6, -15, -22, -30, -37]),
  64. (9,1,array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 30, 30], array[ -1, -2, -2, -3, -4, -4, -4, -4, -5, -6, -14, -20, -27, -34]);
  65. create sequence calc_wind_speed_height_adjustment_seq;
  66. drop table if exists calc_wind_speed_height_adjustment;
  67. create table calc_wind_speed_height_adjustment
  68. (
  69. id integer not null primary key default nextval('public.calc_wind_speed_height_adjustment_seq'),
  70. calc_height_id integer not null,
  71. values integer[] not null,
  72. delta integer not null
  73. );
  74. <<<<<<< Updated upstream
  75. insert into calc_wind_speed_height_adjustment(calc_height_id, values, delta)
  76. values
  77. (10, array[3, 4, 5, 6, 7, 7, 8, 9, 10, 11, 12, 12], 0),
  78. (11, array[4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 1),
  79. (12, array[4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16], 2),
  80. (13, array[4, 5, 7, 8, 8, 9, 11, 12, 13, 15, 15, 16], 2),
  81. (14, array[4, 6, 7, 8, 9, 10, 11, 13, 14, 15, 17, 17], 3),
  82. (15, array[4, 6, 7, 8, 9, 10, 11, 13, 14, 16, 17, 18], 3),
  83. (16, array[4, 6, 8, 9, 9, 10, 12, 14, 15, 16, 18, 19], 3),
  84. (17, array[5, 6, 8, 9, 10, 11, 12, 14, 15, 17, 18, 19], 4),
  85. (18, array[5, 6, 8, 9, 10, 11, 12, 14, 16, 18, 19, 20],4)
  86. ;drop type if exists temperature_adjustment cascade;
  87. =======
  88. truncate table calc_wind_speed_height_adjustment;
  89. insert into calc_wind_speed_height_adjustment(calc_height_id, values, delta)
  90. values
  91. (1, array[3, 4, 5, 6, 7, 7, 8, 9, 10, 11, 12, 12], 0),
  92. (2, array[4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 1),
  93. (3, array[4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16], 2),
  94. (4, array[4, 5, 7, 8, 8, 9, 11, 12, 13, 15, 15, 16], 2),
  95. (5, array[4, 6, 7, 8, 9, 10, 11, 13, 14, 15, 17, 17], 3),
  96. (6, array[4, 6, 7, 8, 9, 10, 11, 13, 14, 16, 17, 18], 3),
  97. (7, array[4, 6, 8, 9, 9, 10, 12, 14, 15, 16, 18, 19], 3),
  98. (8, array[5, 6, 8, 9, 10, 11, 12, 14, 15, 17, 18, 19], 4),
  99. (9, array[5, 6, 8, 9, 10, 11, 12, 14, 16, 18, 19, 20], 4);
  100. drop type if exists temperature_adjustment cascade;
  101. >>>>>>> Stashed changes
  102. create type temperature_adjustment as
  103. (
  104. calc_height_id integer,
  105. height integer,
  106. <<<<<<< Updated upstream
  107. =======
  108. >>>>>>> Stashed changes
  109. temperature_deviation integer
  110. );
  111. drop type if exists wind_direction_adjustment cascade;
  112. create type wind_direction_adjustment as
  113. (
  114. calc_height_id integer,
  115. height integer,
  116. wind_speed_deviation integer,
  117. wind_deviation integer
  118. );
  119. <<<<<<< Updated upstream
  120. create or replace procedure public.temp_dev_calc(
  121. =======
  122. end$$;
  123. do $$
  124. begin
  125. create or replace procedure public.calculate_temperature_deviation(
  126. >>>>>>> Stashed changes
  127. in pmt_measurement_type_id integer,
  128. in pmt_temperature numeric(8,2),
  129. inout pmt_adjustments public.temperature_adjustment[]
  130. )
  131. language 'plpgsql'
  132. as $body$
  133. declare
  134. var_row record;
  135. var_index integer;
  136. var_header_adj integer[];
  137. var_right_index integer;
  138. var_left_index integer;
  139. var_header_index integer;
  140. var_dev integer;
  141. var_table integer[];
  142. var_adj public.temperature_adjustment;
  143. var_table_row text;
  144. begin
  145. if not exists (
  146. select 1
  147. from public.calc_height_adjustment as t1
  148. inner join public.calc_temperature_height_adjustment as t2
  149. on t2.calc_height_id = t1.id
  150. where t1.measurment_type_id = pmt_measurement_type_id
  151. ) then
  152. raise exception 'недостаточно данных';
  153. end if; raise notice '| высота | поправка |';
  154. raise notice '|----------|-----------|'; for var_row in
  155. select t2.*, t1.height
  156. from public.calc_height_adjustment as t1
  157. inner join public.calc_temperature_height_adjustment as t2
  158. on t2.calc_height_id = t1.id
  159. where t1.measurment_type_id = pmt_measurement_type_id
  160. loop
  161. var_index := pmt_temperature::integer;
  162. var_header_adj := (select values from public.calc_header_adjustment
  163. where id = var_row.calc_temperature_header_id and header = 'table2');
  164. if array_length(var_header_adj, 1) = 0 then
  165. raise exception 'высота % - некорректные параметры', var_row.height;
  166. end if; if array_length(var_header_adj, 1) < var_index then
  167. raise exception 'высота % - некорректные параметры', var_row.height;
  168. end if;
  169. var_right_index := abs(var_index % 10);
  170. var_header_index := abs(var_index) - var_right_index;
  171. if pmt_temperature >= 0 then
  172. var_table := var_row.positive_values;
  173. else
  174. var_table := var_row.negative_values;
  175. end if; if var_header_index = 0 then
  176. var_header_index := 1;
  177. end if; var_left_index := var_header_adj[var_header_index];
  178. if var_left_index = 0 then
  179. var_left_index := 1;
  180. end if;
  181. var_dev := var_table[var_left_index] + var_table[var_right_index]; select '|' || lpad(var_row.height::text, 10, ' ') || '|' || lpad(var_dev::text, 11, ' ') || '|'
  182. into var_table_row; raise notice '%', var_table_row; var_adj.calc_height_id := var_row.calc_height_id;
  183. var_adj.height := var_row.height;
  184. var_adj.temperature_deviation := var_dev;
  185. pmt_adjustments := array_append(pmt_adjustments, var_adj);
  186. end loop; raise notice '|----------|-----------|';
  187. end;
  188. $body$;
  189. <<<<<<< Updated upstream
  190. create or replace procedure public.calculate_wind_speed_deviation(
  191. in pmt_bullet_speed numeric,
  192. in pmt_measurement_type_id integer,
  193. inout pmt_adjustments public.wind_direction_adjustment[]
  194. )
  195. language 'plpgsql'
  196. as $body$
  197. declare
  198. var_row record;
  199. var_index integer;
  200. var_adj public.wind_direction_adjustment;
  201. var_header_adj integer[];
  202. var_header_index integer;
  203. var_table integer[];
  204. var_dev integer;
  205. var_table_row text;
  206. begin
  207. if coalesce(pmt_bullet_speed, -1) < 0 then
  208. raise exception 'некорректные параметры. pmt_bullet_speed=%', pmt_bullet_speed;
  209. end if; if not exists (
  210. select 1 from public.calc_height_adjustment
  211. where measurment_type_id = pmt_measurement_type_id
  212. ) then
  213. raise exception '% отсутствуют значения высот', pmt_measurement_type_id;
  214. end if;
  215. var_index := (pmt_bullet_speed / 10)::integer - 4;
  216. if var_index < 0 then
  217. var_index := 1;
  218. end if;
  219. var_header_adj := (select values from public.calc_header_adjustment
  220. where header = 'table3'
  221. and measurment_type_id = pmt_measurement_type_id);
  222. if array_length(var_header_adj, 1) = 0 then
  223. raise exception 'некорректные данные';
  224. end if; if array_length(var_header_adj, 1) < var_index then
  225. raise exception 'некорректные данные';
  226. end if; raise notice '| высота | поправка |';
  227. raise notice '|----------|-----------|'; for var_row in
  228. select t1.height, t2.*
  229. from calc_height_adjustment as t1
  230. inner join public.calc_wind_speed_height_adjustment as t2
  231. on t2.calc_height_id = t1.id
  232. where t1.measurment_type_id = pmt_measurement_type_id
  233. loop
  234. var_header_index := abs(var_index % 10);
  235. var_table := var_row.values;
  236. var_dev := var_table[var_header_index]; select '|' || lpad(var_row.height::text, 10, ' ') || '|' || lpad(var_dev::text, 11, ' ') || '|'
  237. into var_table_row; raise notice '%', var_table_row; var_adj.calc_height_id := var_row.calc_height_id;
  238. var_adj.height := var_row.height;
  239. var_adj.wind_speed_deviation := var_dev;
  240. var_adj.wind_deviation := var_row.delta;
  241. pmt_adjustments := array_append(pmt_adjustments, var_adj);
  242. end loop; raise notice '|----------|-----------|';
  243. end;
  244. $body$;
  245. create or replace procedure public.calculate_wind_direction_deviation(
  246. =======
  247. create or replace procedure public.calculate_wind_deviation(
  248. in pmt_bullet_speed numeric,
  249. >>>>>>> Stashed changes
  250. in pmt_wind_direction numeric,
  251. in pmt_measurement_type_id integer,
  252. inout pmt_adjustments public.wind_direction_adjustment[]
  253. )
  254. language 'plpgsql'
  255. as $body$
  256. declare
  257. var_row record;
  258. var_adj public.wind_direction_adjustment;
  259. <<<<<<< Updated upstream
  260. begin
  261. for var_row in
  262. select t1.height, t2.*
  263. from calc_height_adjustment as t1
  264. inner join public.calc_wind_speed_height_adjustment as t2
  265. =======
  266. var_header_adj integer[];
  267. var_index integer;
  268. var_header_index integer;
  269. var_table integer[];
  270. var_dev integer;
  271. var_table_row text;
  272. begin
  273. if coalesce(pmt_bullet_speed, -1) < 0 and coalesce(pmt_wind_direction, -1) < 0 then
  274. raise exception 'некорректные параметры. pmt_bullet_speed=% или pmt_wind_direction=%', pmt_bullet_speed, pmt_wind_direction;
  275. end if;
  276. if not exists (
  277. select 1 from public.calc_height_adjustment
  278. where measurment_type_id = pmt_measurement_type_id
  279. ) then
  280. raise exception '% отсутствуют значения высот', pmt_measurement_type_id;
  281. end if;
  282. raise notice '| высота | скорость | направление |';
  283. raise notice '|----------|-----------|-------------|';
  284. for var_row in
  285. select t1.height, t2.*
  286. from calc_height_adjustment as t1
  287. left join public.calc_wind_speed_height_adjustment as t2
  288. >>>>>>> Stashed changes
  289. on t2.calc_height_id = t1.id
  290. where t1.measurment_type_id = pmt_measurement_type_id
  291. loop
  292. var_adj.calc_height_id := var_row.calc_height_id;
  293. var_adj.height := var_row.height;
  294. <<<<<<< Updated upstream
  295. var_adj.wind_speed_deviation := var_row.delta;
  296. var_adj.wind_deviation := pmt_wind_direction + var_row.delta;
  297. pmt_adjustments := array_append(pmt_adjustments, var_adj);
  298. end loop;
  299. end;
  300. $body$;
  301. =======
  302. var_adj.wind_speed_deviation := 0;
  303. var_adj.wind_deviation := 0;
  304. if pmt_bullet_speed is not null then
  305. var_index := (pmt_bullet_speed / 10)::integer - 4;
  306. if var_index < 0 then
  307. var_index := 1;
  308. end if;
  309. var_header_adj := (select values from public.calc_header_adjustment
  310. where header = 'table3'
  311. and measurment_type_id = pmt_measurement_type_id);
  312. if array_length(var_header_adj, 1) = 0 then
  313. raise exception 'некорректные данные для скорости ветра';
  314. end if;
  315. if array_length(var_header_adj, 1) < var_index then
  316. raise exception 'некорректные данные для скорости ветра';
  317. end if;
  318. var_header_index := abs(var_index % 10);
  319. var_table := var_row.values;
  320. var_dev := var_table[var_header_index];
  321. var_adj.wind_speed_deviation := var_dev;
  322. var_adj.wind_deviation := var_row.delta;
  323. end if;
  324. if pmt_wind_direction is not null then
  325. var_adj.wind_deviation := var_adj.wind_deviation + (pmt_wind_direction / 10)::integer; -- Примерная логика
  326. end if;
  327. select '|' || lpad(var_row.height::text, 10, ' ') || '|' ||
  328. lpad(var_adj.wind_speed_deviation::text, 11, ' ') || '|' ||
  329. lpad(var_adj.wind_deviation::text, 13, ' ') || '|'
  330. into var_table_row;
  331. raise notice '%', var_table_row;
  332. pmt_adjustments := array_append(pmt_adjustments, var_adj);
  333. end loop;
  334. raise notice '|----------|-----------|-------------|';
  335. end;
  336. $body$;
  337. end$$;
  338. >>>>>>> Stashed changes
  339. do $$
  340. declare
  341. var_temperature_adjustments public.temperature_adjustment[];
  342. var_wind_speed_adjustments public.wind_direction_adjustment[];
  343. var_wind_direction_adjustments public.wind_direction_adjustment[];
  344. begin
  345. raise notice 'расчет отклонений температуры для ветрового ружья';
  346. <<<<<<< Updated upstream
  347. call public.temp_dev_calc(
  348. =======
  349. call public.calculate_temperature_deviation(
  350. >>>>>>> Stashed changes
  351. pmt_measurement_type_id => 2,
  352. pmt_temperature => 3.0,
  353. pmt_adjustments => var_temperature_adjustments
  354. );
  355. raise notice 'отклонение температуры: %', var_temperature_adjustments;
  356. raise notice 'расчет средней скорости ветра для ветрового ружья';
  357. call public.calculate_wind_speed_deviation(
  358. pmt_bullet_speed => 14.0,
  359. pmt_measurement_type_id => 2,
  360. pmt_adjustments => var_wind_speed_adjustments
  361. );
  362. raise notice 'скорость ветра: %', var_wind_speed_adjustments;
  363. raise notice 'расчет среднего направления ветра для ветрового ружья';
  364. call public.calculate_wind_direction_deviation(
  365. pmt_wind_direction => 45.0,
  366. pmt_measurement_type_id => 2,
  367. pmt_adjustments => var_wind_direction_adjustments
  368. );
  369. raise notice 'среднее направление ветра: %', var_wind_direction_adjustments;
  370. <<<<<<< Updated upstream
  371. end $$;create or replace procedure public.temp_dev_calc_dmk(
  372. =======
  373. end $$;
  374. do $$
  375. begin
  376. create or replace procedure public.calculate_temperature_deviation_dmk(
  377. >>>>>>> Stashed changes
  378. in pmt_measurement_type_id integer,
  379. in pmt_temperature numeric(8,2),
  380. inout pmt_adjustments public.temperature_adjustment[]
  381. )
  382. language 'plpgsql'
  383. as $body$
  384. declare
  385. var_row record;
  386. var_index integer;
  387. var_header_adj integer[];
  388. var_right_index integer;
  389. var_left_index integer;
  390. var_header_index integer;
  391. var_dev integer;
  392. var_table integer[];
  393. var_adj public.temperature_adjustment;
  394. var_table_row text;
  395. begin
  396. if not exists (
  397. select 1
  398. from public.calc_height_adjustment as t1
  399. inner join public.calc_temperature_height_adjustment as t2
  400. on t2.calc_height_id = t1.id
  401. where t1.measurment_type_id = pmt_measurement_type_id
  402. ) then
  403. raise exception 'недостаточно данных';
  404. end if; raise notice '| высота | поправка |';
  405. raise notice '|----------|-----------|'; for var_row in
  406. select t2.*, t1.height
  407. from public.calc_height_adjustment as t1
  408. inner join public.calc_temperature_height_adjustment as t2
  409. on t2.calc_height_id = t1.id
  410. where t1.measurment_type_id = pmt_measurement_type_id
  411. loop
  412. var_index := pmt_temperature::integer;
  413. var_header_adj := (select values from public.calc_header_adjustment
  414. where id = var_row.calc_temperature_header_id and header = 'table2');
  415. if array_length(var_header_adj, 1) = 0 then
  416. raise exception 'высота % - некорректные данные', var_row.height;
  417. end if; if array_length(var_header_adj, 1) < var_index then
  418. raise exception 'высота % - некорректные данные', var_row.height;
  419. end if;
  420. var_right_index := abs(var_index % 10);
  421. var_header_index := abs(var_index) - var_right_index;
  422. if pmt_temperature >= 0 then
  423. var_table := var_row.positive_values;
  424. else
  425. var_table := var_row.negative_values;
  426. end if; if var_header_index = 0 then
  427. var_header_index := 1;
  428. end if; var_left_index := var_header_adj[var_header_index];
  429. if var_left_index = 0 then
  430. var_left_index := 1;
  431. end if;
  432. var_dev := var_table[var_left_index] + var_table[var_right_index]; select '|' || lpad(var_row.height::text, 10, ' ') || '|' || lpad(var_dev::text, 11, ' ') || '|'
  433. into var_table_row; raise notice '%', var_table_row; var_adj.calc_height_id := var_row.calc_height_id;
  434. var_adj.height := var_row.height;
  435. var_adj.temperature_deviation := var_dev;
  436. pmt_adjustments := array_append(pmt_adjustments, var_adj);
  437. end loop; raise notice '|----------|-----------|';
  438. end;
  439. $body$;
  440. create or replace procedure public.calculate_wind_speed_deviation_dmk(
  441. in pmt_ground_wind_speed numeric,
  442. in pmt_measurement_type_id integer,
  443. inout pmt_adjustments public.wind_direction_adjustment[]
  444. )
  445. language 'plpgsql'
  446. as $body$
  447. declare
  448. var_row record;
  449. var_index integer;
  450. var_adj public.wind_direction_adjustment;
  451. var_header_adj integer[];
  452. var_header_index integer;
  453. var_table integer[];
  454. var_dev integer;
  455. var_table_row text;
  456. begin
  457. if coalesce(pmt_ground_wind_speed, -1) < 0 then
  458. raise exception 'некорректные данные. pmt_ground_wind_speed=%', pmt_ground_wind_speed;
  459. end if; if not exists (
  460. select 1 from public.calc_height_adjustment
  461. where measurment_type_id = pmt_measurement_type_id
  462. ) then
  463. raise exception '% - не найдены значения высот в таблице', pmt_measurement_type_id;
  464. end if;
  465. var_index := (pmt_ground_wind_speed / 10)::integer - 4;
  466. if var_index < 0 then
  467. var_index := 1;
  468. end if;
  469. var_header_adj := (select values from public.calc_header_adjustment
  470. where header = 'table3'
  471. and measurment_type_id = pmt_measurement_type_id);
  472. if array_length(var_header_adj, 1) = 0 then
  473. raise exception 'некорректные данные';
  474. end if; if array_length(var_header_adj, 1) < var_index then
  475. raise exception 'некорректные данные';
  476. end if; raise notice '| высота | поправка |';
  477. raise notice '|----------|-----------|'; for var_row in
  478. select t1.height, t2.*
  479. from calc_height_adjustment as t1
  480. inner join public.calc_wind_speed_height_adjustment as t2
  481. on t2.calc_height_id = t1.id
  482. where t1.measurment_type_id = pmt_measurement_type_id
  483. loop
  484. var_header_index := abs(var_index % 10);
  485. var_table := var_row.values;
  486. var_dev := var_table[var_header_index]; select '|' || lpad(var_row.height::text, 10, ' ') || '|' || lpad(var_dev::text, 11, ' ') || '|'
  487. into var_table_row; raise notice '%', var_table_row; var_adj.calc_height_id := var_row.calc_height_id;
  488. var_adj.height := var_row.height;
  489. var_adj.wind_speed_deviation := var_dev;
  490. var_adj.wind_deviation := var_row.delta;
  491. pmt_adjustments := array_append(pmt_adjustments, var_adj);
  492. end loop; raise notice '|----------|-----------|';
  493. end;
  494. $body$;
  495. create or replace procedure public.calculate_wind_direction_deviation_dmk(
  496. in pmt_wind_direction numeric,
  497. in pmt_measurement_type_id integer,
  498. inout pmt_adjustments public.wind_direction_adjustment[]
  499. )
  500. language 'plpgsql'
  501. as $body$
  502. declare
  503. var_row record;
  504. var_adj public.wind_direction_adjustment;
  505. begin
  506. for var_row in
  507. select t1.height, t2.*
  508. from calc_height_adjustment as t1
  509. inner join public.calc_wind_speed_height_adjustment as t2
  510. on t2.calc_height_id = t1.id
  511. where t1.measurment_type_id = pmt_measurement_type_id
  512. loop
  513. var_adj.calc_height_id := var_row.calc_height_id;
  514. var_adj.height := var_row.height;
  515. var_adj.wind_speed_deviation := var_row.delta;
  516. var_adj.wind_deviation := pmt_wind_direction + var_row.delta;
  517. pmt_adjustments := array_append(pmt_adjustments, var_adj);
  518. end loop;
  519. end;
  520. $body$;
  521. <<<<<<< Updated upstream
  522. =======
  523. end$$;
  524. >>>>>>> Stashed changes
  525. do $$
  526. declare
  527. var_temperature_adjustments public.temperature_adjustment[];
  528. var_wind_speed_adjustments public.wind_direction_adjustment[];
  529. var_wind_direction_adjustments public.wind_direction_adjustment[];
  530. begin
  531. raise notice 'расчет отклонений температуры для дмк';
  532. <<<<<<< Updated upstream
  533. call public.temp_dev_calc_dmk(
  534. =======
  535. call public.calculate_temperature_deviation_dmk(
  536. >>>>>>> Stashed changes
  537. pmt_measurement_type_id => 1,
  538. pmt_temperature => 3.0,
  539. pmt_adjustments => var_temperature_adjustments
  540. );
  541. raise notice 'отклонение температуры: %', var_temperature_adjustments;
  542. raise notice 'расчет средней скорости ветра для дмк';
  543. call public.calculate_wind_speed_deviation_dmk(
  544. pmt_ground_wind_speed => 14.0,
  545. pmt_measurement_type_id => 1,
  546. pmt_adjustments => var_wind_speed_adjustments
  547. );
  548. raise notice 'средняя скорость ветра: %', var_wind_speed_adjustments;
  549. raise notice 'расчет среднего направления ветра для дмк';
  550. call public.calculate_wind_direction_deviation_dmk(
  551. pmt_wind_direction => 45.0,
  552. pmt_measurement_type_id => 1,
  553. pmt_adjustments => var_wind_direction_adjustments
  554. );
  555. raise notice 'среднее направление ветра: %', var_wind_direction_adjustments;
  556. end $$;