Merge and aggregate datasets: Difference between revisions
Content added Content deleted
(→{{header|Prolog}}: Use date atoms in XSB implementation) |
(→{{header|Prolog}}: Update both versions) |
||
Line 846: | Line 846: | ||
Mean is Sum/Count. |
Mean is Sum/Count. |
||
test :- |
|||
⚫ | |||
summaryDates(Id, Lastname, LastDate), |
|||
⚫ | |||
Bag), writeln(Bag), fail. |
|||
fail. |
|||
test :- |
|||
⚫ | |||
summaryScores(Id, Lastname, ScoreSum, ScoreMean), |
|||
⚫ | |||
fail.</lang> |
|||
{{output}} |
{{output}} |
||
<pre> |
<pre>summaryDates(1001,Hopper,2020-11-19) |
||
summaryDates(2002,Gosling,2020-10-08) |
|||
[summaryScores(1001,Hopper,17.4,5.8),summaryScores(2002,Gosling,6.8,6.8),summaryScores(4004,Wirth,15.4,7.7)] |
|||
⚫ | |||
⚫ | |||
summaryScores(1001,Hopper,17.4,5.8) |
|||
summaryScores(2002,Gosling,6.8,6.8) |
|||
summaryScores(4004,Wirth,15.4,7.7) |
|||
false.</pre> |
false.</pre> |
||
Implemented using XSB Prolog: |
Implemented using XSB Prolog: |
||
<lang prolog>:- import bagMax/2, bagCount/2, bagSum/2 from aggregs. |
<lang prolog>:- import bagMax/2, bagCount/2, bagSum/2, bagReduce/4 from aggregs. |
||
:- import |
:- import julian_date/7, date_string/3 from iso8601. |
||
:- import load_csv/2, add_cvt_type_hook/2 from proc_files. |
|||
?- add_cvt_type_hook(date,date_converter(_,_)). |
|||
⚫ | |||
patient(4004,'Wirth'). |
|||
patient(3003,'Kemeny'). |
|||
patient(2002,'Gosling'). |
|||
patient(5005,'Kurtz'). |
|||
visit(2002,'2020-09-10',6.8). |
|||
visit(1001,'2020-09-17',5.5). |
|||
visit(4004,'2020-09-24',8.4). |
|||
visit(2002,'2020-10-08',nan). |
|||
visit(1001,'',6.6). |
|||
⚫ | |||
⚫ | |||
visit(1001,'2020-11-19',5.3). |
|||
date_converter(Atom,Date) :- date_string('YYYY-MM-DD',Date,Atom). |
|||
number_datecodes(Number, [Y1,Y2,Y3,Y4,45,M1,M2,45,D1,D2]) :- |
|||
number_codes(Number, [Y1,Y2,Y3,Y4,M1,M2,D1,D2]). |
|||
:- load_csv('visit.csv',visit(integer,date,float)). |
|||
:- load_csv('patient.csv',patient(integer,atom)). |
|||
summaryDates(Id, Lastname, LastDate) :- |
summaryDates(Id, Lastname, LastDate) :- |
||
bagMax(date_number(Id), LastDateNumber), |
bagMax(date_number(Id), LastDateNumber), |
||
patient(Id,Lastname), |
patient(Id,Lastname), |
||
julian_date(LastDateNumber, Y, M, D, _, _, _), |
|||
date_string('YYYY-MM-DD', date(Y,M,D), LastDate). |
|||
atom_codes(LastDate, LastDateCodes). |
|||
summaryScores(Id, Lastname, Sum, Mean) :- |
summaryScores(Id, Lastname, Sum, Mean) :- |
||
bagSum(scores(Id), Sum), |
bagSum(scores(Id), Sum), |
||
bagCount(scores(Id), Count), |
bagCount(scores(Id), Count), |
||
⚫ | |||
patient(Id,Lastname), |
|||
⚫ | |||
⚫ | |||
test :- |
|||
⚫ | |||
⚫ | |||
test :- |
|||
⚫ | |||
⚫ | |||
/* Put hilog declarations together */ |
/* Put hilog declarations together */ |
||
date_number(Id)(Number) :- |
date_number(Id)(Number) :- |
||
visit(Id, |
visit(Id, date(Y,M,D), _), |
||
julian_date(Number, Y, M, D, _, _, _). |
|||
atom_codes(Date,Codes), |
|||
number_datecodes(Number,Codes). |
|||
scores(Id)(Score) :- |
scores(Id)(Score) :- |
||
visit(Id, _, Score), Score>0.0. %% nan.0 is very small |
|||
:- hilog maximum. |
:- hilog maximum. |
||
Line 905: | Line 910: | ||
sum(X,Y,Z) :- Z is X+Y. |
sum(X,Y,Z) :- Z is X+Y. |
||
:- hilog successor. |
:- hilog successor. |
||
successor(X,_Y,Z) :- Z is X+1. |
successor(X,_Y,Z) :- Z is X+1.</lang> |
||
⚫ | |||
⚫ | |||
Bag), writeln(Bag), fail. |
|||
⚫ | |||
⚫ | |||
Bag), writeln(Bag), fail.</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |