SysJobHistory run_duration to DD:HH:MM:SS - tsql

Im trying to convert time from SysJobsHistory run_duration seconds to show Days, hours, minutes and seconds.
SELECT
STUFF(STUFF(STUFF(RIGHT(REPLICATE('0', 8) + CAST(jh.run_duration as varchar(8)), 8), 3, 0, ':'), 6, 0, ':'), 9, 0, ':') as 'StepLastRunDuration',
FROM msdb.dbo.sysjobhistory jh
I have one outcome which is 00:25:30:18 (25hr, 30min, 18sec) however I want it to show 01:01:30:18 (1day, 1hr, 30min, 18sec)

SELECT
STUFF(STUFF(STUFF(
RIGHT('00' + TRIM(STR((jh.run_duration / 240000))), 2) +
RIGHT('00' + TRIM(STR((jh.run_duration / 10000) % 24)), 2) +
RIGHT('0000' + STR(jh.run_duration), 4)
, 3, 0, ':'), 6, 0, ':'), 9, 0, ':') AS 'StepLastRunDuration'
FROM msdb.dbo.sysjobhistory jh

Related

Read data set line by line and convert each space seperated line to comma seperated in Scala

I have a dasaset of length 200 and length of each row of data is also 200. This dataset is space separated. Here is sample dataset (first row).
-0.1100208269729097 0.1248460463105589 -0.01559138588255286 -0.01625839428292603 -0.05323888667281371 0.06722185430549973 -0.0490877148079949 -0.05039368886946847 0.0897270838973875 0.00754589058726465 -0.06693447805463611 -0.1193740974362337 -0.02214573804045866 0.02930806967704801 -0.009567144727872222 -0.02288991169653539 0.04256313697292451 -0.08190168271952417 0.008274133732539695 -0.02299227162395361 0.0111923018567119 -0.009872522389769637 0.06866110814693088 0.04622954799009332 0.05498202029091768 -0.06672541846259043 -0.05130079655965012 0.1107659505844031 0.07912810279475517 0.02246390669165305 -0.06997067603392053 -0.02069109953229961 -0.05191987832821615 -0.01971016519416264 -0.008691704006401698 -0.02963829527404451 0.02332929010677706 -0.1035585589634834 0.03801924036385142 -0.07035181096148016 -0.02460761051792025 0.05545479574143786 0.06632500394350074 -0.01693623441811409 -0.0202000922412099 0.0387732166529701 -0.06835009268170482 -0.06684471565316714 0.09737868086728406 -0.03776102176325794 -0.03087980353481784 -0.04630278791951752 -0.1129739647985331 0.09622849675187727 0.05975310144103099 -0.08083650075114446 0.05258346559791484 0.05583993856089118 -0.03916345795047688 -0.2981097687887527 0.04087798461219992 0.07153463501552468 0.07113045074135986 0.01717619972420815 -0.01893649865573213 -0.007503347735166889 0.06551854299072507 -0.005153581328393866 -0.08659840104899437 0.04864888731854276 0.08965801176651583 -0.004562179660153576 -0.1252787635844004 0.06896990208188783 -0.003925090827015415 -0.05755687748680104 -0.02544736897698906 0.02530385776038159 -0.125784848738536 0.07433650535349738 0.02153916317259382 0.04738213124034089 -0.03299623626264642 0.02073383160046674 -0.008966711746564809 0.04983292315200202 0.01974696673478601 -0.04419678420395467 -0.02442715323795661 -0.0694663145847256 0.1101497271416977 0.04200639135007367 -0.06082113335723243 -0.01473508072467703 0.01142600017146485 -0.03532257289246362 -0.02260329422449697 0.05396810070565884 0.1581078158241939 -0.05426153505070038 -0.01534772560258162 -0.04461245038675606 -0.05082561044342486 0.003953621713155758 -0.09395992245069541 0.02029879424655968 0.09397373054431565 -0.01540603811173099 -0.00188325436669238 0.07341578917873427 -0.07930228379622654 -0.01519407550785842 0.01388266474816023 0.09152064522133056 0.0106446218365201 -0.2157572256227169 0.04804075039482639 0.01970079327929429 -0.04738197196862703 0.06770927522186629 0.1006260778362594 -0.06299061441376895 0.02961951153113571 0.01572783315493193 0.1349089347411493 -0.0242042239418958 -0.07337276266118564 -0.09620055007994345 0.04754719051788902 -0.04777964847293222 0.01477148963357754 0.06678924792453055 0.05579081171364433 -0.03405429131223387 0.03615588517175376 -0.1554971840439641 -0.04581567263300179 -0.07873107398807083 0.05966093431149457 -0.128446162280915 -0.05912532817875745 0.1194692701951161 0.1103496401807509 0.0153127716173752 0.01607453121383664 -0.07114032721360454 0.03276185612322021 0.1169776569257143 0.07706242373764424 0.04889932405415184 0.0008715101384050066 0.006894007893755344 0.04519320187367908 -0.001306669064508431 0.0291067296150834 -0.02697983215093226 -0.07374490898814057 -0.04408652590757124 0.118965444980577 0.08668199929217432 0.02704832616237655 0.01473294258443707 0.02049896556673346 -0.0569226246137925 -0.0120183686689177 -0.1007080842912528 0.03517628230997978 -0.2003177929062758 0.01491215547976228 0.04590546935765301 0.1670139443078561 -0.05992676476987346 0.07038240324837636 -0.003567431692839979 0.08197255057946093 -0.01384071718153512 0.01443837418022523 -0.0393556604031245 0.003264844777785919 -0.190455395258628 -0.09122702488367737 -0.007113243408323287 0.1221344569965773 -0.06583221256210335 0.002275841418885295 -0.02418590378253777 -0.02462843336523757 -0.1054326841702153 -0.009075125286585313 0.05233463322601897 -0.09944517224527978 0.08201627957443283 0.1144830692826725 -0.1488155291532296 0.001711351371442085 0.06463339531524601 0.02089587578959802 -0.05699940762150812 0.01798950350182588 -0.01642350646709232
I tried in following way to convert it into comma seperated data. Here is my code
val bufferedSource1 = Source.fromFile(Path1 + name)
val lines1 : Iterator[String] = bufferedSource1.getLines()
val lines2 = lines1.toArray
println( lines2(0).toList )
Result of last line of code is
List(-, 0, ., 1, 1, 0, 0, 2, 0, 8, 2, 6, 9, 7, 2, 9, 0, 9, 7, , 0, ., 1, 2, 4, 8, 4, 6, 0, 4, 6, 3, 1, 0, 5, 5, 8, 9, , -, 0, ., 0, 1, 5, 5, 9, 1, 3, 8, 5, 8, 8, 2, 5, 5, 2, 8, 6, , -, 0, ., 0, 1, 6, 2, 5, 8, 3, 9, 4, 2, 8, 2, 9, 2, 6, 0, 3, , -, 0, ., 0, 5, 3, 2,.........
This is returning me single character but I want complete row that will be space separated. How can I fix This issue?
here is remaining code for conversion
val data1 : Array[Array[Double]] = lines2.flatMap{xz : String =>
Seq (xz.replaceAll(" ", ",").split(",").map(_.toDouble) )
}.toArray
import spark.implicits._
val ds = List("-0.1100208269729097 0.1248460463105589 -0.01559138588255286 -0.01625839428292603 -0.05323888667281371 0.06722185430549973 -0.0490877148079949 -0.05039368886946847 0.0897270838973875 0.00754589058726465 -0.06693447805463611 -0.1193740974362337 -0.02214573804045866 0.02930806967704801 -0.009567144727872222 -0.02288991169653539 0.04256313697292451 -0.08190168271952417 0.008274133732539695 -0.02299227162395361 0.0111923018567119 -0.009872522389769637 0.06866110814693088 0.04622954799009332 0.05498202029091768 -0.06672541846259043 -0.05130079655965012 0.1107659505844031 0.07912810279475517 0.02246390669165305 -0.06997067603392053 -0.02069109953229961 -0.05191987832821615 -0.01971016519416264 ","-0.1100208269729097 0.1248460463105589 -0.01559138588255286 -0.01625839428292603 -0.05323888667281371 0.06722185430549973 -0.0490877148079949 -0.05039368886946847 0.0897270838973875 0.00754589058726465 -0.06693447805463611 -0.1193740974362337 -0.02214573804045866 0.02930806967704801 -0.009567144727872222 -0.02288991169653539 0.04256313697292451 -0.08190168271952417 0.008274133732539695 -0.02299227162395361 0.0111923018567119 -0.009872522389769637 0.06866110814693088 0.04622954799009332 0.05498202029091768 -0.06672541846259043 -0.05130079655965012 0.1107659505844031 0.07912810279475517 0.02246390669165305 -0.06997067603392053 -0.02069109953229961 -0.05191987832821615 -0.01971016519416264 ").toDS()
ds.map(i=> i.split(" ").mkString(",")).show(false)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|-0.1100208269729097,0.1248460463105589,-0.01559138588255286,-0.01625839428292603,-0.05323888667281371,0.06722185430549973,-0.0490877148079949,-0.05039368886946847,0.0897270838973875,0.00754589058726465,-0.06693447805463611,-0.1193740974362337,-0.02214573804045866,0.02930806967704801,-0.009567144727872222,-0.02288991169653539,0.04256313697292451,-0.08190168271952417,0.008274133732539695,-0.02299227162395361,0.0111923018567119,-0.009872522389769637,0.06866110814693088,0.04622954799009332,0.05498202029091768,-0.06672541846259043,-0.05130079655965012,0.1107659505844031,0.07912810279475517,0.02246390669165305,-0.06997067603392053,-0.02069109953229961,-0.05191987832821615,-0.01971016519416264|
|-0.1100208269729097,0.1248460463105589,-0.01559138588255286,-0.01625839428292603,-0.05323888667281371,0.06722185430549973,-0.0490877148079949,-0.05039368886946847,0.0897270838973875,0.00754589058726465,-0.06693447805463611,-0.1193740974362337,-0.02214573804045866,0.02930806967704801,-0.009567144727872222,-0.02288991169653539,0.04256313697292451,-0.08190168271952417,0.008274133732539695,-0.02299227162395361,0.0111923018567119,-0.009872522389769637,0.06866110814693088,0.04622954799009332,0.05498202029091768,-0.06672541846259043,-0.05130079655965012,0.1107659505844031,0.07912810279475517,0.02246390669165305,-0.06997067603392053,-0.02069109953229961,-0.05191987832821615,-0.01971016519416264|
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

prolog - Generating dates between dates

I need to generate all dates between two given dates.
My predicate date_between(DateLow, DateHigh, X) works correctly:
?- date_between(date(2020,2,15), date(2020,2,25), X).
X = date(2020, 2, 15) ;
X = date(2020, 2, 16) ;
....
X = date(2020, 2, 25) .
But I think predicate is too clumsy. Is there another approach to do the same but more elegant?
Should I translate back and forth Date to Seconds (Stamp) and Seconds to Date?
I have to compare dates through conversion in seconds?
You can see my code:
date_between(DateLow, DateHigh, DateLow) :-
datestd_stamp(DateLow, StampLow),
datestd_stamp(DateHigh, StampHigh),
StampLow =< StampHigh.
date_between(DateLow, DateHigh, X) :-
datestd_stamp(DateLow, StampLow),
datestd_stamp(DateHigh, StampHigh),
StampLow < StampHigh,
DateLow = date(Y,M,D),
Dnxt is D + 1,
date_time_stamp(date(Y,M,Dnxt,0,0,0,0,-,-), StampNext),
stamp_date_time(StampNext, Dat, 0),
date_time_value(date, Dat, DateNxt),
date_between(DateNxt, DateHigh, X).
datestd_stamp(Data, Stamp) :-
Data = date(Y,M,D),
date_time_stamp(date(Y,M,D,0,0,0,0,-,-), StampTmp),
round(StampTmp, Stamp).
I tried to improve the predicate. The execution time has definitely been reduced.
The predicate has become simpler and faster.
Old version:
?- time((bagof(X, (date_between(date(2020,1,1), date(2100,12,31), X)), Ls))).
% 680,466 inferences, 0.149 CPU in 0.149 seconds (100% CPU, 4563901 Lips)
Ls = [date(2020, 1, 1), date(2020, 1, 2), date(2020, 1, 3),
New version:
?- time((bagof(X, (date_between2(date(2020,1,1), date(2100,12,31), X)), Ls))).
% 207,106 inferences, 0.066 CPU in 0.066 seconds (100% CPU, 3157900 Lips)
Ls = [date(2020, 1, 1), date(2020, 1, 2), date(2020, 1, 3),
You can see new version of predicate:
date_between2(DateLow, DateHigh, DateLow) :-
DateLow #=< DateHigh.
date_between2(DateLow, DateHigh, X) :-
DateLow #< DateHigh,
DateLow = date(Y,M,D),
Dnxt is D + 1,
date_time_stamp(date(Y,M,Dnxt,0,0,0,0,-,-), StampNext),
stamp_date_time(StampNext, Dat, 0),
date_time_value(date, Dat, DateNxt),
date_between2(DateNxt, DateHigh, X).

rrule dates are offset by a week

I'm getting an unexpected result using the python-dateutil rrule module and I'm wondering if this is WAI.
I'm dynamically creating the rrule using:
dtstart = datetime.date(2019, 1, 7)
until = datetime.date(2029, 11, 29)
freq = MONTHLY
byweekday=MO(2)
interval = 4
This results in the following rrule
DTSTART:20190107T000000
RRULE:FREQ=MONTHLY;INTERVAL=4;UNTIL=20291129T000000;BYDAY=+2MO
However, when generating the dates (looping on the rrule for this python module), I get the following dates:
[datetime.datetime(2019, 1, 14, 0, 0),
datetime.datetime(2019, 5, 13, 0, 0),
datetime.datetime(2019, 9, 9, 0, 0),
datetime.datetime(2020, 1, 13, 0, 0),
datetime.datetime(2020, 5, 11, 0, 0),
datetime.datetime(2020, 9, 14, 0, 0),
datetime.datetime(2021, 1, 11, 0, 0),
datetime.datetime(2021, 5, 10, 0, 0),
datetime.datetime(2021, 9, 13, 0, 0),
datetime.datetime(2022, 1, 10, 0, 0),
datetime.datetime(2022, 5, 9, 0, 0),
datetime.datetime(2022, 9, 12, 0, 0),
datetime.datetime(2023, 1, 9, 0, 0),
datetime.datetime(2023, 5, 8, 0, 0),
datetime.datetime(2023, 9, 11, 0, 0),
datetime.datetime(2024, 1, 8, 0, 0),
datetime.datetime(2024, 5, 13, 0, 0),
datetime.datetime(2024, 9, 9, 0, 0),
datetime.datetime(2025, 1, 13, 0, 0),
datetime.datetime(2025, 5, 12, 0, 0),
datetime.datetime(2025, 9, 8, 0, 0),
datetime.datetime(2026, 1, 12, 0, 0),
datetime.datetime(2026, 5, 11, 0, 0),
datetime.datetime(2026, 9, 14, 0, 0),
datetime.datetime(2027, 1, 11, 0, 0),
datetime.datetime(2027, 5, 10, 0, 0),
datetime.datetime(2027, 9, 13, 0, 0),
datetime.datetime(2028, 1, 10, 0, 0),
datetime.datetime(2028, 5, 8, 0, 0),
datetime.datetime(2028, 9, 11, 0, 0),
datetime.datetime(2029, 1, 8, 0, 0),
datetime.datetime(2029, 5, 14, 0, 0),
datetime.datetime(2029, 9, 10, 0, 0)]
Notice that the first date is offset by a week! Why is this the case? And is this a bug in the library?
Thanks,
David
It's not a bug in the library. 2019-01-14 is the first date which matches your rule (it's the 2nd Monday of January 2019). Apparently python-dateutil has chosen to not include the start date you provide, which is completely legit.
RRULE is specified in RFC 5545, which states in Section 3.8.5.3 (under "Description"):
The recurrence set generated with a "DTSTART" property
value not synchronized with the recurrence rule is undefined.
Which essentially means there is no right or wrong interpretation because the input data is "broken" if the start date doesn't match the rule.
Note, many other implementations would probably return both, your start date 2019-01-07 and the result 2019-01-14. I don't think any implementation would omit 2019-01-14, simply because it is the first date which matches the rule. It's debatable whether the start date 2019-01-07 should be in the results or not, but 2019-01-14 should definitely be in there.
In Python by_weekly code could be implemented like this.
from calendar import isleap
from datetime import datetime
from dateutil.rrule import rrule, DAILY, WEEKLY, MONTHLY
def bi_weekly(start_date=datetime.now(),count=53,interval=2):
"""
dateTImeSart = bi_weekly(datetime.strptime('2021-01-01', '%Y-%m-%d'),53)
print(dateTImeSart[0].strftime("%Y-%m-%d"))
print(dateTImeSart[1].strftime("%Y-%m-%d"))
print(dateTImeSart[50].strftime("%Y-%m-%d"))
print(dateTImeSart[51].strftime("%Y-%m-%d"))
print(dateTImeSart[52].strftime("%Y-%m-%d"))
2021-01-01
2021-01-15
2022-12-02
2022-12-16
2022-12-30
"""
# returns the datetime for an year and calculates them for 1 By weekly
return list(rrule(WEEKLY, count=count,interval=interval, dtstart=start_date))

ZXing library Reed Solomon example

I want to try the ReedSolomonDecoder from the ZXing library on the example given on page 10 of this paper
Basically, it encodes the message
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
using the generator polynomial
x^4 + 15x^3 + 3x^2 + x + 12
which results in
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 3, 12, 12
I want to decode this in the following manner:
int[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 3, 12, 12};
GenericGF field = new GenericGF(?, 16, 1); // what integer should I use for primitive here?
ReedSolomonDecoder decoder = new ReedSolomonDecoder(field);
decoder.decode(data, 4);
I don't know how to create a GenericGF object from the given generator polynomial. I know that it expects a binary integer representation of the polynomial, but to do that, I would need the polynomial to be in an irreducible form, i.e. all the coefficients to be either 0 or 1. How can I achieve that from this given generator polynomial?
I'm pretty new to this as well but I think you would want to use
public static GenericGF AZTEC_PARAM = new GenericGF(0x13, 16, 1);

Variable to generate previous data in ssis Package?

I have created a variable which will checks present date how can i get previous date using below expression?
"/Report-"+(DT_WSTR,4)YEAR(GETDATE())
+ RIGHT("0"+(DT_WSTR, 2) MONTH(GETDATE()) ,2)
+ RIGHT("0"+(DT_WSTR, 2) DAY(GETDATE()) ,2)+ ".csv"
Result:
/Report-20140210.csv
How can i get if i need previous date
/Report-20140209.csv
You will need to apply the dateadd expression to GetDate indicating that you wish to subtract one day.
"/Report-" +
(DT_WSTR, 4) YEAR(dateadd("d", -1, getdate()))
+ RIGHT("0" + (DT_WSTR, 2) MONTH(dateadd("d", -1, getdate())), 2)
+ RIGHT("0" + (DT_WSTR, 2) DAY(dateadd("d", -1, getdate())), 2)
+ ".csv"
Yields /Report-20140209.csv
"/Report-" +
(DT_WSTR, 4) YEAR(dateadd("d", -1, getdate()))
+ RIGHT("0" + (DT_WSTR, 2) MONTH(dateadd("d", -1, getdate())), 2)
+ RIGHT("0" + (DT_WSTR, 2) DAY(dateadd("d", -1, getdate())), 2)
+ ".csv