How to detect an event and ensure its the first (earliest event that occurred? - sql

I am attempting to extract data from a large patient database using SQL. I need to detect when an event occurred. In this case, it will be a decrease in SpO2 by 10% from when treatment started. It needs to be the earliest time point when it decreased. Example 100%-95-92-97-88-92-89 only the 88 is what I will need. The tricky part begins as patients might have two treatments throughout care. I need to compare these treatments to observe which treatment is the best. An example of the data is below.
The patient will have treatment A until treatment B starts or until the final reading and vis versa. the SpO2 values with ** are the ones I need to extract
Date
Time
SpO2
Treatment
05/19/22
18:23
100
N/A
05/19/22
18:24
95
A
05/19/22
18:25
90
N/A
05/19/22
18:26
85
N/A
05/19/22
18:27
N/A
B
05/19/22
18:27
90
N/A
05/19/22
18:28
85
N/A
05/19/22
18:29
80
N/A
05/19/22
18:30
78
N/A
05/19/22
18:31
76
N/A
What I'm hoping the final table looks like is
Date
Time
SpO2
Treatment
05/19/22
18:23
100
N/A
05/19/22
18:24
95
A
05/19/22
18:26
85
N/A
05/19/22
18:27
N/A
B
05/19/22
18:27
90
N/A
05/19/22
18:29
80
N/A
If you can please help, that would be amazing and thank you very much.

Related

Trying to pull records from a .DAT file but my results are blank. I think I have misunderstood how to use file management

So I am trying to pull the records from a file formatted as follows (The reason I am asking this, despite similar questions existing is because I am on a much more "beginner" level than those questions covered.)
ELF-CAL
6669
6434
6564
1032
1098
1829
2608
7322
2690
7061
1664
5769
ELF #16160
1082
3958
5272
2188
5618
3418
2302
2926
3338
1082
2024
4195
4083
ELF #13276
5581
3421
3403
4356
2989
1278
1868
3630
4702
3409
4887
2383
ELF #17104
7496
5265
8078
8788
7402
3601
2641
1252
4994
ELF #14074
7524
8889
9290
8892
5785
2163
1074
6747
ELF #17452
8006
12427
7919
4012
6850
ELF #134591
26861
ELF #113028
12695
12762
11006
15937
ELF #117218
12408
17554
11415
ELF #11118
7240
6400
3431
1032
3283
4667
6100
5076
1101
6952
3527
ELF #17633
4385
4510
4073
3052
11738
ELF #133554
ELF #13448
16054
10839
ELF #14496
2697
4731
5150
5327
4039
4004
2148
6150
4001
2882
5780
4327
ELF #14095
2064
6701
3828
2427
4775
2583
2000
1390
7391
1701
3796
ELF #110355
1262
8781
6350
ELF #111053
11527
1389
6007
12383
11033
ELF #17951
4258
9815
10061
7579
3769
11431
ELF #13597
35622
ELF #12129
2994
4260
5269
4179
1612
3509
3581
4544
3713
3202
6458
1203
1095
ELF #117196
13475
12666
ELF #13549
6432
6593
6723
1272
4023
2112
2844
5135
5103
1585
4773
5635
ELF #18731
16378
5076
2999
ELF #111136
1525
8684
9731
9753
5366
7399
ELF #18996
1483
4922
1191
2761
(It goes on and on. Each occurence of "ELF #" Is supposed to indicate a new record)
So my code looks like the following, and it just displays blank spaces when I run it. Any suggestions on why I am getting file management wrong? And how should I fix it
IDENTIFICATION DIVISION.
PROGRAM-ID. COBSHL03.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT ELF-INNPUT ASSIGN TO "C:\Users\dsdsd\Desktop\innput.DAT"
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS DOING-ITS-BEST.
DATA DIVISION.
FILE SECTION.
FD ELF-INNPUT.
01 ELF-RECS.
05 ELF-CAL PIC X(9).
05 ELF-NUM PIC X(10).
WORKING-STORAGE SECTION.
01 CACLULATIONS.
03 COUNT-OF-ELF PIC X(6).
03 ELF-CAL-TOTAL PIC 9(6).
01 DOING-ITS-BEST PIC X(900).
PROCEDURE DIVISION.
PROGRAM-BEGIN.
OPEN INPUT ELF-INNPUT.
DISPLAY ELF-RECS.
CLOSE ELF-INNPUT.
PROGRAM-DONE.
STOP RUN.
You OPEN and CLOSE the file, it looks like you've missed to READ it, likely in a loop checking the defined io-status (which is a PIC XX item).

How to add +/- 1% to a condition?

ID Open Close SMA EMA
30 UNITY 11.50 11.53 12.576 12.715570
31 UNITY 11.44 11.34 12.399 12.626823
32 UNITY 11.26 11.74 12.273 12.569609
33 UNITY 11.72 11.61 12.150 12.507699
34 UNITY 11.51 11.43 11.994 12.438170
35 UNITY 11.85 11.17 11.844 12.356352
How to make a condition which reflects if the close is +/- 1% or precisely equal to the EMA?
THANKS!
numpy.isclose(a, b, rtol=1e-02)
rtol is the relative tolerance, which is 0.01 for +/- 1%.

Fuel Consumption and mileage from OBD2 port parameters.

I am computing my fuel consumption from OBD2 parameter. MAF to be specific and I am receiving data on per second basis. Here is an section of my data.
TS RS EngS MAF R MAP EL TD Travel
14:41:22 31 932 1056 98 23978 12130
14:41:23 29 2084 2639 107 23210 12130
14:41:24 32 2154 3867 149 38826 12130
14:41:25 36 2426 4683 184 36266 12130
14:41:26 39 2391 3031 133 682 12130
14:41:27 40 1784 2794 132 30634 12130
14:41:28 42 1864 2853 140 30378 12130
14:41:29 43 1953 2900 132 29098 12130
14:41:30 46 2031 3017 135 29098 12130
14:41:31 45 2027 2969 126 20138 12130
14:41:32 47 2122 4253 174 42154 12130
14:41:33 51 2220 4722 183 20906 12130
Where
TS : Time Stamp,
RS : Road Speed,
EngS : Engine Speed,
MAF R : Mass Air Flow Rate,
MAP Mass Air Pressure,
EL : Engine Load,
TD Travel : Total Distance Traveled
So basically from this data I am trying to compute my Instantaneous Fuel Consumption and The Mileage in KMPL.
For that, Since The Data is per second i am taking MAF of each row and using this formula,
Fuel Consumption = MAF/(14.7*710),
where 14.7 = ideal air/fuel ratio,
and 710 is density of gasoline in grams/L
So, this should give my consumption. and I am calculating the distance(in KM) from RS /3600. And further dividing distance by fuel consumption to get mileage. However the calculation is coming horribly wrong. The mileage of my car is around 14KMPL. Here are my results.
TS Distance (inKM) Fuel Consum(L) Mileage(KMPL)
14:41:22 0.0086111111 0.1008355216 0.0853975957
14:41:23 0.0080555556 0.2519933158 0.0319673382
14:41:24 0.0088888889 0.369252805 0.0240726374
14:41:25 0.01 0.4471711626 0.0223628016
14:41:26 0.0108333333 0.2894246837 0.0374305785
14:41:27 0.0111111111 0.2667939842 0.0416467828
14:41:28 0.0116666667 0.2724277871 0.0428248043
14:41:29 0.0119444444 0.2769157317 0.0431338602
14:41:30 0.0127777778 0.2880878491 0.0443537546
14:41:31 0.0125 0.2835044163 0.0440910239
14:41:32 0.0130555556 0.4061112437 0.0321477323
14:41:33 0.0141666667 0.4508952017 0.0314189785
Can someone tell what am I doing so wrong that the computation is so wrong. As the formulas are simple there isn't much scope to do error.Thank You.
MAF is in g/s
MAF(g/s) * 1/14.7 * 1L/710g = Fuel Consumption in L/s Units
Speed (V) is in KPH (Km/hr) so V(Km/hr) * (1hr/3600s) = v KPS(Km/s)
so FC(L/s) / v (Km/s) = L/Km
you want Km/L so v/Fc so your final formula is
KmPL = V * 1/ 3600 * 1/MAF * 14.7 * 710
Divide the MAF by 14.7 to get Grams of fuel per Sec
next divide by 454 to get lbs fuel/sec
next divide 6.701 to get fuel/sec
multiply by 3600 to get gallons/ hr
other case GPH=MAF*0.0805 next MPG=MPH?GPH

Excel 2010 Macro to compare more then two columns for finding the matched value via macro or VBA

I have two sheets (sheet1 and sheet 2) in sheet1 there is more than two columns I want to match or check the difference value; column name are Chq. No., Name and Amount in sheet1 and sheet2.
Sheet 1
Date Chq. No. Name Amount
9/22/2015 22 REETA 1,400.00
9/21/2015 30 SUMIRTA 1,400.00
8/18/2015 31 NIRDUL KUMARI 200.00
8/21/2015 56 JAGDAMBA MISHRA 200.00
8/21/2015 58 ARUN KUMARI 200.00
8/21/2015 59 SANTOSH KUMARI 200.00
Sheet2
9/22/2015 22 REETA 1,400.00
9/21/2015 30 SUMIRTA 1,400.00
8/18/2015 33 NIRDUL KUMARI 200.00
8/21/2015 55 JAGDAMBA MISHRA 200.00
8/21/2015 58 ARUN KUMARI 200.00
8/21/2015 60 SANTOSH KUMARI 200.00
My side I am sharing the example with I am facing in actual, kindly help me.
Nitin in your case Cheque no is best field to match both databases,, you can use this one
=IF(ISERROR(MATCH(Sheet1! $B2,Sheet2! $B$2:$B$10,0)),"No match in B","")
Or you can use either this,
=INDEX(Sheet1! $A$2:$C$6,MATCH(Sheet2! $A 2,Sheet1! $A$2:$C$6,0))

How to read data on a specific row from excel by asking the name of that row?

I have the following excel file:
W1000x554 1032 408 52.1 29.5 70700 12300
W1000x539 1030 407 51.1 28.4 68700 12000
W1000x483 1020 404 46 25.4 61500 10700
W1000x443 1012 402 41.9 23.6 56400 9670
W1000x412 1008 402 40 21.1 52500 9100
W1000x371 1000 400 36.1 19 47300 8140
W1000x321 990 400 31 16.5 40900 6960
W1000x296 982 400 27.1 16.5 37800 6200
W1000x584 1056 314 64 36.1 74500 12500
I want to define a function that can ask the user for one of the first column's names and then read all the relevant data of that row later.
For example if the user defines W1000x412 then read : 1008 402 40 21.1 52500 9100.
Any ideas?
I suspect what #Marc means is that a formula such as in J2 below (copied across and down as necessary) will 'pick out' the values you want. It is not clear to me from your question whether these should be kept separate (as in Row2 of example) or strung together (CONCATENATE [&] as in J7 of example, where these are space [" "] delimited):
I am also not entirely sure about your 'define a function' but have assumed you do not require a UDF.
I have used Row1 to provide the offset for VLOOKUP, to save adjusting manually the formula for each column.
ColumnI is the expected user input, that might be best by selection from a Data Validation List with Source $A$2:$A$10.