I have a website with application pool "accounts.services"
I want to use xpolog to group all logs by their title
and order them by their count
I have tried:
(Computer = VM2014.conduit.local ) in app.accountsservices | count | group by Source | order by count des
but go syntax error
what is wrong?
Computer contains VM2014 in app.accountsservices | count | group by source | order by count desc
Related
I'm looking to return encounters later than 12-17-2020 for each patient involving any of the antibiotics. I'm expecting many results, as querying by one antibiotic at a time shows me. But when I string them together in rlike, it only returns results for one patient for the first antibiotic, amikacin. Is there something wrong in the syntax?
CREATE TABLE tsri.antibiotics AS
SELECT * FROM observation_fact_meds
WHERE start_date > "2020-12-17"
AND encounter_num in (select distinct encounter_num from visit_dimension where patient_num in ('000000', '000001', '000002', '000003', '000004', '000006', '000007') and INOUT_CD in ('Inpatient'))
AND DESCRIPTION rlike ('amikacin| amoxicillin| amoxicillin-clavulanate| Amphotericin B| ampicillin| ampicillin-sulbactam | azithromycin| aztreonam| bacitracin| cefazolin | efepime | cefiderocol| cefotaxime | cefoxitin| ceftaroline| ceftazidime | ceftazidime-avibactam| ceftriaxone | cefuroxime | cephalexin| ciprofloxacin| clarithromycin| clindamycin | Cloxacillin| Cotrimoxazole | dapsone| erythromycin| gentamicin| imipenem| imipenem-cilastatin| isoniazid| lefamulin| levofloxacin| linezolid| meropenem| metronidazole| Nafcillin| Nystatin| penicillin| pentamidine| piperacillin-tazobactam| Piperacillin | rifampin | sulfamethoxazole-trimethoprim | TNF Antimicrobial Med| tobramycin| vancomycin')
Remove the space before pattern - pls put exact string you are looking for a string seperate them only by pipe.
DESCRIPTION rlike ('amikacin|amoxicillin|...
Is there a way to reshape the data in pig?
The data looks like this -
id | p1 | count
1 | "Accessory" | 3
1 | "clothing" | 2
2 | "Books" | 1
I want to reshape the data so that the output would look like this--
id | Accessory | clothing | Books
1 | 3 | 2 | 0
2 | 0 | 0 | 1
Can anyone please suggest some way around?
If its a fixed set of product line the below code might help, otherwise you can go for a custom UDF which helps in achieving the objective.
Input : a.csv
1|Accessory|3
1|Clothing|2
2|Books|1
Pig Snippet :
test = LOAD 'a.csv' USING PigStorage('|') AS (product_id:long,product_name:chararray,rec_cnt:long);
req_stats = FOREACH (GROUP test BY product_id) {
accessory = FILTER test BY product_name=='Accessory';
clothing = FILTER test BY product_name=='Clothing';
books = FILTER test BY product_name=='Books';
GENERATE group AS product_id, (IsEmpty(accessory) ? '0' : BagToString(accessory.rec_cnt)) AS a_cnt, (IsEmpty(clothing) ? '0' : BagToString(clothing.rec_cnt)) AS c_cnt, (IsEmpty(books) ? '0' : BagToString(books.rec_cnt)) AS b_cnt;
};
DUMP req_stats;
Output :DUMP req_stats;
(1,3,2,0)
(2,0,0,1)
I am fairly new to SSRS but am having a problem double summing when using Lookupsets as output. I have the following table and query which does work
Query for Hours_DataSet
SELECT CallbackDate, SUM(TelemarketingHours) AS DailyHours,
(SELECT SUM(TelemarketingHours) AS Expr1
FROM CallbackTbl) AS HoursPTD
FROM CallbackTbl AS CallbackTbl_1
GROUP BY CallbackDate
Definition of Matrix
| [CallbackDate] | Weekly totals
________________________________________________________________
Hours | [Sum(DailyHours]) | Sum(Sum(DailyHours))
The output is this:
12/01/2014 | 12/02/2014 | 12/03/2014 | 12/04/2014 | 12/05/2014| Weekly totals|
28.75 | 42 | 42.25 | 40.25 | 37.50 | 190.75
In another table I need to calculate the appointments per hour and total appointments per hour for the week. So I set the main data-set to be the number of appointments and use lookupset and custom code to do the summing.
Everything works well for one level of sum. I need to recreate the 190.75 number and use it in the as the denominator in the calculation for number of appointments per hour for the week.
Query for Positive_DataSet:
SELECT MainHistory_1.REALDATE, StatusTbl.Status, COUNT (MainHistory_1.DBRECID) AS Positives, StatusTbl.Code,
(SELECT COUNT(DBRECID) AS Expr1
FROM MainHistory
WHERE (REALDATE > CONVERT(DATETIME, #StartDate, 102)) AND (REALDATE < CONVERT(DATETIME, #EndDate, 102))) AS TotalCalls
FROM MainHistory AS MainHistory_1 INNER JOIN
StatusTbl ON MainHistory_1.STATUS = StatusTbl.Status
GROUP BY MainHistory_1.REALDATE, StatusTbl.Status, StatusTbl.Code
HAVING (StatusTbl.Code = 'P') AND (MainHistory_1.REALDATE > CONVERT(DATETIME, #StartDate, 102)) AND (MainHistory_1.REALDATE < CONVERT(DATETIME, #EndDate, 102))
My Matrix looks like this:
[REALDATE]| Weekly Totals
EXPR | EXPR
where the expressions are
FORMAT(Code.CalcPerHour(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"Hours_DataSet"),SUM(Fields!Positives.Value)),"Fixed")
Sum(Sum(Fields!Positives.Value))/SUM(code.CalcPTD(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"Hours_DataSet")))
My custom code is this:
PUBLIC SHARED FUNCTION CalcPerHour(Hours AS OBJECT, Totals AS OBJECT) AS DECIMAL
DIM i AS INTEGER
DIM PerHour AS DECIMAL
FOR i=0 TO UBOUND(Hours)
IF CINT(Hours(i)) < > 0 THEN
PerHour = PerHour + (CDEC(Totals)/CDEC(Hours(i)))
END IF
Next i
RETURN PerHour
END FUNCTION
PUBLIC SHARED FUNCTION CalcPTD(LookupArray AS Array) AS DECIMAL
DIM I AS INTEGER
DIM Total AS DECIMAL
Total = 0
FOR i = 0 to UBOUND(LookupArray)
Total = Total + CDEC(LookupArray(i))
NEXT i
RETURN Total
END FUNCTION
My Output is this:
12/01/2014 | 12/02/2014 | 12/03/2014 | 12/04/2014 | 12/05/2014 | Weekly totals|
1.63 | 1.79 | 1.75 | 1.59 | 1.41 | .87
The numbers corresponding to the days of the week are correct.
The number I should be getting for a total is
313/190.75 = 1.64
If I break it down and just look at the sum like this:
sum(Code.CalcPTD(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"Hours_DataSet")))
I get the result of 352.50
If I count the number of items like this:
Count(Code.CalcPTD(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMA(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"Hours_DataSet")))
I get the result of 9
If I count distinct the number of items like this:
CountDistinct(Code.CalcPTD(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"Hours_DataSet")))
I get the expected 5
I tried to write code for a distinct sum but it wouldn't return a single result but a series of 5 corresponding to the days of the week and I have to display in a single cell.
Any help would be appreciated. I know its kinda complicated. If you have questions or need further clarification please let me know.
So I figured out the answer on my own. To get a grand total of a variable within a dataset you can use SUM(fields!VarName.Value,"DataSet") and it does it for you.
I use AJAX mechanism to set create or modify records in this table:
table:
id | item_type | item_id | creator_id | attitude
1 | exemplar | 3 | 33 | 1
2 | exemplar | 4 | 33 | 0
3 | exemplar | 3 | 35 | 1
In plain English: there are many exemplars to choose for one user. A given user can only set only one exemplar to value 1. In this particular case Exemplar #3 is active (attitude = 1). I want to set its "attitude" to 0 and in the same controller method where I have the below code.
The below code creates a new record for an exemplar which has never been chosen before, or changes the value of 'attitude column.
$user_id = Auth::user()->id;
$countatt = $exemplar->attitudes()->where('creator_id', $user_id)->first();
if (!$countatt)
{
$countatt = new Userattitude;
$countatt->creator_id = $user_id;
$countatt->item_type = 'exemplar';
$countatt->item_id = $exemplar_id;
}
$countatt->attitude = $value; // $value = 1
$countatt->save();
Problem to solve:
1. how, using the best practices, set all other records of the same user (creator_id) and exemplar_id to 0
My best guess isbe to put the below 4 lines before the code quoted above:
$oldactive= Exemplar::where('creator_id', $user_id)->where(exemplar_id, $exemplar_id)->first();
$zeroing_attitude= $oldactive->attitudes()->first();
$zeroing_attitude->attitude = 0;
$zeroing_attitude->save();
;
The above solution works only in case when there is only one exemplar with value of 'attitude' set to 1. But in the future I want to allow users to have multiple exemplars active. I am not familiar with Eloquent enough to rewrite the logic for multiple active Exemplars.
Sometimes there will be no active Exemplars set, which means that this collection would be empty
$oldactive= Exemplar::where('creator_id', $user_id)->where(exemplar_id, $exemplar_id)->first();
How should I skip executing the rest of the code in such case? By adding IF as below?
if($oldactive) {}
Thank you.
$oldactive= Exemplar::where('creator_id', $user_id)->where(exemplar_id,$exemplar_id)->first();
foreach($oldactive->attitudes() as $zeroing_attitude){
$zeroing_attitude->attitude = 0;
$zeroing_attitude->save();
}
If i have a table in a WebFocus Raport design
+--------+---------+--------+---------+
| left_1 | right_1 | left_2 | right_2 |
+--------+---------+--------+---------+
| v11 | p11 | v21 | v21 |
+--------+---------+--------+---------+
| v12 | p12 | v22 | v22 |
....
How to do a such table with syllabus column titles:
+-------+-------+-------+-------+
| One | Two |
+-------+-------+-------+-------+
| left | right | left | right |
+-------+-------+-------+-------+
| v11 | p11 | v21 | v21 |
+-------+-------+-------+-------+
| v12 | p12 | v22 | v22 |
....
Thank you
Sorry for the delay of the answer :)
To rename columns, with the AS command. Example:
TABLE FILE SYSTABLE
PRINT NAME
COMPUTE LEFT1/A3 = 'v11'; AS 'left';
COMPUTE RIGHT1/A3 = 'p11'; AS 'right';
COMPUTE LEFT2/A3 = 'v21'; AS 'left';
COMPUTE RIGHT2/A3 = 'p21'; AS 'right';
IF RECORDLIMIT EQ 10
END
To put the heading columns, you can work with the ACROSS command but it will be more tricky that if u use simply SUBHEAD. With the same example:
TABLE FILE SYSTABLE
PRINT NAME NOPRINT
COMPUTE LEFT1/A3 = 'v11'; AS 'left';
COMPUTE RIGHT1/A3 = 'p11'; AS 'right';
COMPUTE LEFT2/A3 = 'v21'; AS 'left';
COMPUTE RIGHT2/A3 = 'p21'; AS 'right';
IF RECORDLIMIT EQ 10
ON TABLE SUBHEAD
"<+0>One<+0> Two"
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
UNITS=IN, PAGESIZE='Letter',
LEFTMARGIN=0.500000, RIGHTMARGIN=0.500000,
TOPMARGIN=0.500000, BOTTOMMARGIN=0.500000,
SQUEEZE=ON, GRID=OFF, ORIENTATION=LANDSCAPE, $
TYPE=REPORT,FONT='ARIAL',SIZE=9,$
TYPE=TABHEADING,HEADALIGN=BODY,$
TYPE=TABHEADING, LINE=1, ITEM=1, COLSPAN=2, SQUEEZE=ON,$
TYPE=TABHEADING, LINE=1, ITEM=2, COLSPAN=2, SQUEEZE=ON,$
ENDSTYLE
END
Hope it helps!
I'm not entirely sure if you load the headers as a field or if that is the field name
But this might help you
Define fields
TITL1/A3 = 'One';
TITL2/A3 = 'Two';
BLANK/A1 = '';
Edit the Left and Right title fields to remove the _1 or _2
Print the fields BY BLANK NOPRINT
Add
ON BLANK SUBHEAD
"
You can also add more rows to the subhead if you need more titles
You can easily do it by embedding HTML/CSS scripts in report(.fex) file.
just add the HTML/css code at the end of the file.
For eg.
-HTMLFORM BEGIN // to start styling your generated report table with HTML/CSS
TABLE tr
td:first-child // applies on 1st row ONLY.It can be td or th.
{
colspan = "2"; //to merge 2 columns
}
-HTMLFORM END //end HTML.
So the first row must have two cells having title "ONE" and "TWO"(in your case), and both cells must have property of colspan = "2"
Also you can refer:
Colspan propery from here
manipulating first row of table from here
Second option is to write the whole code in a file and save it in .htm/.html format and just insert the file in to WEBFOCUS(.fex) file.For eg.
-HTMLFORM BEGIN
-INCLUDE HTML_FILE.HTML
-HTMLFORM END
Hope it helps.Thanks.