forked from nozberkaryaindonesia/influent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataViewTables_mssql.sql
More file actions
791 lines (723 loc) · 26.2 KB
/
DataViewTables_mssql.sql
File metadata and controls
791 lines (723 loc) · 26.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
/*
* Copyright 2013-2016 Uncharted Software Inc.
*
* Property of Uncharted(TM), formerly Oculus Info Inc.
* https://uncharted.software/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-- ------------------------------------------------------------------------------
-- Influent Data View Script
-- Run the following script in steps. At each step, please ensure that you
-- modify the script to reflect your own data and the type of Influent
-- installation you would like.
-- ------------------------------------------------------------------------------
-- ------------------------------------------------------------------------------
-- STEP 1: No modifications required
--
-- Run the following scripts to create link flow tables
-- ------------------------------------------------------------------------------
--
-- FLOW AGGREGATION TABLE
-- Used to build the aggregate flow diagrams
--
-- Columns:
-- FromEntityId - entity UID that is the source of the aggregated
-- transactions
-- FromEntityType - type of src entity: O = owner summary, A = account,
-- S = cluster summary entity
-- ToEntityId - entity UID that is the target of the aggregated
-- transactions
-- ToEntityType - type of dst entity: O = owner summary, A = account,
-- S = cluster summary entity
-- FirstTransaction - datetime of first transaction
-- LastTransaction - datetime of last transaction
-- Amount - aggregate amount
--
create table LinkFlow(
FromEntityId varchar(100),
FromEntityType varchar(1),
ToEntityId varchar(100),
ToEntityType varchar(1),
FirstTransaction datetime,
LastTransaction datetime,
Amount float,
constraint pk_lf_from_to primary key (FromEntityId, ToEntityId)
);
--
-- TIME SERIES FLOW AGGREGATION TABLES
-- Used to build the aggregate flow diagrams (aggregated by time)
-- and used to build the highlighted sub-section of the time series
-- charts on entities.
--
-- Columns:
-- FromEntityId - entity UID that is the source of the aggregated
-- transactions
-- FromEntityType - type of src entity: O = owner summary,
-- A = account, S = cluster summary entity
-- ToEntityId - entity UID that is the target of the aggregated transactions
-- ToEntityType - type of dst entity: O = owner summary, A = account,
-- S = cluster summary entity
-- Amount - aggregate amount for this time period
-- PeriodDate - start of the time period
--
create table LinkFlowDaily(
FromEntityId varchar(100),
FromEntityType varchar(1),
ToEntityId varchar(100),
ToEntityType varchar(1),
Amount float,
PeriodDate datetime,
constraint pk_lfd_from_to_date primary key (FromEntityId, ToEntityId, PeriodDate)
);
create table LinkFlowWeekly(
FromEntityId varchar(100),
FromEntityType varchar(1),
ToEntityId varchar(100),
ToEntityType varchar(1),
Amount float,
PeriodDate datetime,
constraint pk_lfw_from_to_date primary key (FromEntityId, ToEntityId, PeriodDate)
);
create table LinkFlowMonthly(
FromEntityId varchar(100),
FromEntityType varchar(1),
ToEntityId varchar(100),
ToEntityType varchar(1),
Amount float,
PeriodDate datetime,
constraint pk_lfm_from_to_date primary key (FromEntityId, ToEntityId, PeriodDate)
);
create table LinkFlowQuarterly(
FromEntityId varchar(100),
FromEntityType varchar(1),
ToEntityId varchar(100),
ToEntityType varchar(1),
Amount float,
PeriodDate datetime,
constraint pk_lfq_from_to_date primary key (FromEntityId, ToEntityId, PeriodDate)
);
create table LinkFlowYearly(
FromEntityId varchar(100),
FromEntityType varchar(1),
ToEntityId varchar(100),
ToEntityType varchar(1),
Amount float,
PeriodDate datetime,
constraint pk_lfy_from_to_date primary key (FromEntityId, ToEntityId, PeriodDate)
);
-- ------------------------------------------------------------------------------
-- STEP 2: Modifications required
--
-- Modify this to pull data from your raw data. Add any transactions to
-- cluster summaries as well.
-- ------------------------------------------------------------------------------
--
-- you will need to modify the following:
--
-- source_id - the column in your raw data table that corresponds to the
-- source entity id
-- dest_id - the column in your raw data table that corresponds to the
-- target entity id
-- amount - the column in your raw data table that corresponds to the
-- transaction amount
-- dt - the column in your raw data table that corresponds to the
-- transaction timestamp
-- YOUR_RAW_DATA - the name of your raw transaction data table
--
insert into LinkFlowDaily
select
[source_id],
'A',
[dest_id],
'A',
sum([amount]),
convert(varchar(50), [dt], 101)
from YOUR_RAW_DATA
group by [source_id], [dest_id], convert(varchar(50), [dt], 101)
-- create LinkFlowDaily indices
create index ix_lfd_from_date_to_amount on LinkFlowDaily (FromEntityId, PeriodDate, ToEntityId, Amount);
create index ix_lfd_to_date_from_amount on LinkFlowDaily (ToEntityId, PeriodDate, FromEntityId, Amount);
-- ------------------------------------------------------------------------------
-- STEP 3: Modifications required
--
-- Run the following scripts to create entity tables. If you are building
-- a multi-type installation, you are required to repeat this step for each
-- entity type
-- ------------------------------------------------------------------------------
--
-- ENTITY AGGREGATION TABLE
-- Used to build the and
--
-- Columns:
-- EntityId - entity UID
-- IncomingLinks - the number of incoming links to this entity
-- UniqueIncomingLinks - the number of entities that have outgoing links to
-- this entity
-- OutgoingLinks - the number of outgoing links from this entity
-- UniqueOutgoingLinks - the number of entities that have incoming links
-- from this entity
-- NumLinks - the total number of links to and from this entity
-- MaxTransaction - the maximum transaction size to or from this entity
-- AvgTransaction - the average transaction size to and from this entity
-- StartDate - the earliest transaction to or from this entity
-- EndDate - the latest transaction to or from this entity
--
-- you will need to modify the following:
--
-- EntitySummary - if you are building a multi-type installation, you
-- should rename this table to include the type name
-- (e.g. EntitySummaryMyType)
-- Additional columns - you can add type specific entity columns that
-- Influent can search on and display.
create table EntitySummary(
EntityId varchar(100) primary key,
IncomingLinks int not null,
UniqueIncomingLinks int not null,
OutgoingLinks int not null,
UniqueOutgoingLinks int not null,
NumLinks int,
MaxTransaction float,
AvgTransaction float,
StartDate datetime,
EndDate datetime
-- additional type specific columns added here --
);
--
-- TIME SERIES FLOW AGGREGATION TABLES
-- Used to build the time series charts on entities (aggregated by time).
--
-- Columns:
-- EntityId - entity UID
-- PeriodDate - start of the time period
-- InboundAmount - aggregate credits for this time period
-- IncomingLinks - unique inbound transactions by entity
-- OutboundAmount - aggregate debits for this time period
-- OutgoingLinks - unique outbound transactions by entity
--
create table EntityDaily(
EntityId varchar(100),
PeriodDate datetime,
InboundAmount float,
IncomingLinks int,
OutboundAmount float,
OutgoingLinks int,
constraint pk_ed_id_date primary key (EntityId, PeriodDate)
);
create table EntityWeekly(
EntityId varchar(100),
PeriodDate datetime,
InboundAmount float,
IncomingLinks int,
OutboundAmount float,
OutgoingLinks int,
constraint pk_ew_id_date primary key (EntityId, PeriodDate)
);
create table EntityMonthly(
EntityId varchar(100),
PeriodDate datetime,
InboundAmount float,
IncomingLinks int,
OutboundAmount float,
OutgoingLinks int,
constraint pk_em_id_date primary key (EntityId, PeriodDate)
);
create table EntityQuarterly(
EntityId varchar(100),
PeriodDate datetime,
InboundAmount float,
IncomingLinks int,
OutboundAmount float,
OutgoingLinks int,
constraint pk_eq_id_date primary key (EntityId, PeriodDate)
);
create table EntityYearly(
EntityId varchar(100),
PeriodDate datetime,
InboundAmount float,
IncomingLinks int,
OutboundAmount float,
OutgoingLinks int,
constraint pk_ey_id_date primary key (EntityId, PeriodDate)
);
--
-- you will need to modify the following:
--
-- EntitySummary - if you are building a multi-type installation, you
-- should rename this table to include the type name
-- (e.g. EntitySummaryMyType)
-- source_id - the column in your raw data table that corresponds to the
-- source entity id
-- dest_id - the column in your raw data table that corresponds to the
-- target entity id
-- amount - the column in your raw data table that corresponds to the
-- transaction amount
-- dt - the column in your raw data table that corresponds to the
-- transaction timestamp
-- YOUR_RAW_DATA - the name of your raw transaction data table
-- where clause - if you are building a multi-type installation, you should
-- uncomment this line and replace 'myType' with the actual
-- name of your entity type
--
insert into EntitySummary(
EntityId,
IncomingLinks,
UniqueIncomingLinks,
OutgoingLinks,
UniqueOutgoingLinks,
NumLinks,
MaxTransaction,
AvgTransaction,
StartDate,
EndDate
)
select
EntityId,
sum(IncomingLinks) as IncomingLinks,
sum(UniqueIncomingLinks) as UniqueIncomingLinks,
sum(OutgoingLinks) as OutgoingLinks ,
sum(UniqueOutgoingLinks) as UniqueOutgoingLinks,
sum(NumLinks) as NumLinks,
max(MaxTransaction) as MaxTransaction,
sum(TotalTransactions) / sum(NumLinks) as AvgTransaction,
min(StartDate) as StartDate,
max(EndDate) as EndDate
from (
select [dest_id] as EntityId,
count([source_id]) as IncomingLinks,
count( distinct [source_id] ) as UniqueIncomingLinks,
0 as OutgoingLinks,
0 as UniqueOutgoingLinks,
count([dest_id]) as NumLinks,
max([amount]) as MaxTransaction,
sum([amount]) as TotalTransactions,
min([dt]) as StartDate,
max([dt]) as EndDate
from YOUR_RAW_DATA
group by [dest_id]
union
select [source_id] as EntityId,
0 as IncomingLinks,
0 as UniqueIncomingLinks,
count([dest_id]) as OutgoingLinks,
count( distinct [dest_id] ) as UniqueOutgoingLinks,
sum( case when [source_id] <> [dest_id] then 1 else 0 end ) as NumLinks,
max([amount]) as MaxTransaction,
sum([amount]) as TotalTransactions,
min([dt]) as StartDate,
max([dt]) as EndDate
from YOUR_RAW_DATA
group by [source_id]
)q
-- where EntityId like 'myType.%' --
group by EntityId
--
-- you will need to modify the following:
--
-- Additional columns - if you added additional columns to your
-- EntitySummary table, you will want to
-- uncomment and set them in the code below
-- EntitySummary - if you are building a multi-type
-- installation, you should rename this
-- table to include the type name
-- (e.g. EntitySummaryMyType)
-- ES.EntityId = EP.id - - you may need to modify this line if the
-- EntityId and the raw data id differ
-- (i.e. with multi-type installations, the
-- EntityId might look like 'myType.123'
-- whereas the raw data id is '123'. You
-- will need to account for these
-- differences)
-- YOUR_RAW_ENTITY_PROPERTIES_DATA - the name of your raw transaction data
-- table
--
--update EntitySummary
--set
-- -- additional type specific columns added here
-- -- (e.g. EntitySummary.myColumn = YOUR_RAW_ENTITY_PROPERTIES_DATA.myColumn)
--from EntitySummary ES
--inner join
--YOUR_RAW_ENTITY_PROPERTIES_DATA EP
--on ES.EntityId = EP.id
--
-- you will need to modify the following:
--
-- EntitySummary - if you are building a multi-type installation, you
-- should rename this table to include the type name
-- (e.g. EntitySummaryMyType)
create index ix_es_id on EntitySummary (EntityId);
-- ------------------------------------------------------------------------------
-- STEP 4: No modifications required
--
-- The following section will collect data from LinkFlowDaily and requires no
-- modifications
-- ------------------------------------------------------------------------------
-- build LinkFlowWeekly time series aggregation
insert into LinkFlowWeekly
select
FromEntityId,
FromEntityType,
ToEntityId,
ToEntityType,
sum(Amount),
convert(varchar(50), (dateadd(dd, @@DATEFIRST - datepart(dw, PeriodDate) - 6, PeriodDate)), 101)
from LinkFlowDaily
group by
FromEntityId,
FromEntityType,
ToEntityId,
ToEntityType,
convert(varchar(50), (dateadd(dd, @@DATEFIRST - datepart(dw, PeriodDate) - 6, PeriodDate)), 101);
-- build LinkFlowMonthly time series aggregation
insert into LinkFlowMonthly
select
FromEntityId,
FromEntityType,
ToEntityId,
ToEntityType,
sum(Amount),
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/' + convert(varchar(2), datepart(mm, PeriodDate)) + '/01', 101)
from LinkFlowDaily
group by
FromEntityId,
FromEntityType,
ToEntityId,
ToEntityType,
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/' + convert(varchar(2), datepart(mm, PeriodDate)) + '/01', 101);
-- build LinkFlowQuarterly time series aggregation
insert into LinkFlowQuarterly
select
FromEntityId,
FromEntityType,
ToEntityId,
ToEntityType,
sum(Amount),
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/' + case when datepart(q, PeriodDate)=1 then '01' when datepart(q, PeriodDate)=2 then '04' when datepart(q, PeriodDate)=3 then '07' when datepart(q, PeriodDate)=4 then '010' end + '/01', 101)
from LinkFlowMonthly
group by
FromEntityId,
FromEntityType,
ToEntityId,
ToEntityType,
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/' + case when datepart(q, PeriodDate)=1 then '01' when datepart(q, PeriodDate)=2 then '04' when datepart(q, PeriodDate)=3 then '07' when datepart(q, PeriodDate)=4 then '010' end + '/01', 101);
-- build LinkFlowYearly time series aggregation
insert into LinkFlowYearly
select
FromEntityId,
FromEntityType,
ToEntityId,
ToEntityType,
sum(Amount),
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/01/01', 101)
from LinkFlowMonthly
group by
FromEntityId,
FromEntityType,
ToEntityId,
ToEntityType,
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/01/01', 101);
-- create LinkFlow time series aggregation indices
create index ix_lfw_from_date_to_amount on LinkFlowWeekly (FromEntityId, PeriodDate, ToEntityId, Amount);
create index ix_lfw_to_date_from_amount on LinkFlowWeekly (ToEntityId, PeriodDate, FromEntityId, Amount);
create index ix_lfm_from_date_to_amount on LinkFlowMonthly (FromEntityId, PeriodDate, ToEntityId, Amount);
create index ix_lfm_to_date_from_amount on LinkFlowMonthly (ToEntityId, PeriodDate, FromEntityId, Amount);
create index ix_lfq_from_date_to_amount on LinkFlowQuarterly (FromEntityId, PeriodDate, ToEntityId, Amount);
create index ix_lfq_to_date_from_amount on LinkFlowQuarterly (ToEntityId, PeriodDate, FromEntityId, Amount);
create index ix_lfy_from_date_to_amount on LinkFlowYearly (FromEntityId, PeriodDate, ToEntityId, Amount);
create index ix_lfy_to_date_from_amount on LinkFlowYearly (ToEntityId, PeriodDate, FromEntityId, Amount);
-- build LinkFlow aggregation table
insert into LinkFlow
select
FromEntityId,
FromEntityType,
ToEntityId,
ToEntityType,
min(PeriodDate),
max(PeriodDate),
sum(Amount)
from LinkFlowDaily
group by
FromEntityId,
FromEntityType,
ToEntityId,
ToEntityType;
create index ix_lf_to_from on LinkFlow (ToEntityId, FromEntityId);
create index ix_lf_from_to on LinkFlow (FromEntityId, ToEntityId);
-- build EntityDaily
create table temp_ids (Entity varchar(100));
create index tids on temp_ids (Entity);
insert into temp_ids
select distinct FromEntityId
from LinkFlowYearly
union
select distinct ToEntityId
from LinkFlowYearly;
insert into EntityDaily
select
Entity,
PeriodDate,
sum(case when ToEntityId = Entity and FromEntityType = 'A' then Amount else 0 end),
sum(case when ToEntityId = Entity and FromEntityType = 'A' then 1 else 0 end), -- calculate inbound degree
sum(case when FromEntityId = Entity and ToEntityType = 'A' then Amount else 0 end),
sum(case when FromEntityId = Entity and ToEntityType = 'A' then 1 else 0 end), -- calculate outbound degree
from temp_ids
join LinkFlowDaily
on FromEntityId = Entity or ToEntityId = Entity
group by Entity, PeriodDate;
-- cleanup
drop table temp_ids;
-- build EntityWeekly time series aggregation
insert into EntityWeekly
select
EntityId,
convert(varchar(50), (dateadd(dd, @@DATEFIRST - datepart(dw, PeriodDate) - 6, PeriodDate)), 101),
sum(InboundAmount),
sum(IncomingLinks),
sum(OutboundAmount),
sum(OutgoingLinks),
0
from EntityDaily
group by
EntityId,
convert(varchar(50), (dateadd(dd, @@DATEFIRST - datepart(dw, PeriodDate) - 6, PeriodDate)), 101);
-- build EntityMonthly time series aggregation
insert into EntityMonthly
select
EntityId,
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/' + convert(varchar(2), datepart(mm, PeriodDate)) + '/01', 101),
sum(InboundAmount),
sum(IncomingLinks),
sum(OutboundAmount),
sum(OutgoingLinks),
0
from EntityDaily
group by
EntityId,
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/' + convert(varchar(2), datepart(mm, PeriodDate)) + '/01', 101);
-- build EntityQuarterly time series aggregation
insert into EntityQuarterly
select
EntityId,
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/' + case when datepart(q, PeriodDate)=1 then '01' when datepart(q, PeriodDate)=2 then '04' when datepart(q, PeriodDate)=3 then '07' when datepart(q, PeriodDate)=4 then '010' end + '/01', 101),
sum(InboundAmount),
sum(IncomingLinks),
sum(OutboundAmount),
sum(OutgoingLinks),
0
from EntityMonthly
group by
EntityId,
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/' + case when datepart(q, PeriodDate)=1 then '01' when datepart(q, PeriodDate)=2 then '04' when datepart(q, PeriodDate)=3 then '07' when datepart(q, PeriodDate)=4 then '010' end + '/01', 101);
-- build EntityYearly time series aggregation
insert into EntityYearly
select
EntityId,
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/01/01', 101),
sum(InboundAmount),
sum(IncomingLinks),
sum(OutboundAmount),
sum(OutgoingLinks),
0
from EntityQuarterly
group by
EntityId,
convert(varchar(50), convert(varchar(4), datepart(yyyy, PeriodDate)) + '/01/01', 101);
-- create Entity time series aggregation indices
create index ix_ed_id_date_in_out on EntityDaily (EntityId, PeriodDate, InboundAmount, OutboundAmount);
create index ix_ew_id_date_in_out on EntityWeekly (EntityId, PeriodDate, InboundAmount, OutboundAmount);
create index ix_em_id_date_in_out on EntityMonthly (EntityId, PeriodDate, InboundAmount, OutboundAmount);
create index ix_eq_id_date_in_out on EntityQuarterly (EntityId, PeriodDate, InboundAmount, OutboundAmount);
create index ix_ey_id_date_in_out on EntityYearly (EntityId, PeriodDate, InboundAmount, OutboundAmount);
-- ------------------------------------------------------------------------------
-- STEP 5: Modifications required
--
-- The following section will build cluster summary tables. You only need to
-- run this section if you have a dataset that has the potential for
-- extremely large high degree clusters. The cluster summary table will
-- allow the system to still explore these cluster at a high level but will
-- limit in-depth exploration
-- ------------------------------------------------------------------------------
--
-- CLUSTER SUMMARY TABLE
-- Used to summarize an entity with a large number of associated entities
-- (e.g. account owner with a large number of accounts) It is up to each
-- application to determine what cluster summaries to generate based on the
-- size of data
--
-- Columns:
-- EntityId - entity UID of cluster entity
-- Property - name of summary property
-- Tag - Property_Tag to associate with property
-- Type - FL_PropertyType data type of property value (DOUBLE, LONG,
-- BOOLEAN, STRING, DATE, GEO, OTHER)
-- Value - the string representation of the property value
-- Stat - an associated stat for the property value such as frequency
-- or weight
--
-- Note:
-- Cluster summaries that represent an account owner should have an account
-- owner property that associates the entity id of the account owner to the
-- cluster summary. For example:
-- EnitityId = 'cluster123',
-- Property = 'ownerId',
-- Tag = 'ACCOUNT_OWNER',
-- Type = 'String',
-- Value = 'partner123',
-- Stat = 0
--
-- Cluster summaries that do not support branching should have a property of
-- UNBRANCHABLE (by default all cluster summaries are branchable). For
-- example:
-- EnitityId = 'cluster123',
-- Property = 'UNBRANCHABLE',
-- Tag = 'ENTITY_TYPE',
-- Type = 'BOOLEAN',
-- Value = 'true',
-- Stat = 0
--
create table ClusterSummary (
EntityId varchar(100),
Property varchar(50),
Tag varchar(50),
[Type] varchar(50),
[Value] varchar(200),
Stat float,
constraint pk_cs_id_prop_val primary key (EntityId, Property, [Value])
);
--
-- CLUSTER SUMMARY MEMBERS
-- Used to keep track of entities that are members of a cluster summary
-- It is up to each application to determine what cluster summaries to
-- generate based on the size of data
--
-- SummaryId - UID of cluster summary
-- EntityId - member entity UID
--
create table ClusterSummaryMembers (
SummaryId varchar(100),
EntityId varchar(100),
constraint pk_csm_sum_id primary key (SummaryId, EntityId)
);
-- create cluster summary indices
create index ix_cs_id on ClusterSummary (EntityId);
create index ix_csm_sum on ClusterSummaryMembers (SummaryId);
-- ------------------------------------------------------------------------------
-- STEP 6: Modifications required
--
-- The following section will build summary information on the data for
-- display on the summary page
--
-- Modify this section as needed to reflect the nature of your dataset.
-- The first stat in the table should be a description of your dataset. The
-- following inserts show an example of typical summary statistics. Note that
-- you will in most cases want to format the values nicely for reading. The
-- script as is here will simply copy most types of values over in their
-- default format. UnformattedNumeric and UnformattedDatetime are added to
-- provide a reference in case the formatted value corrupts or loses
-- valuable information.
-- ------------------------------------------------------------------------------
create table DataSummary (
SummaryOrder int not null,
SummaryKey varchar(100) not null,
SummaryLabel varchar(1000) null,
SummaryValue text null,
UnformattedNumeric float null,
UnformattedDatetime datetime null,
constraint pk_ds_order primary key (SummaryOrder)
);
-- Modify the following to create a summary description
insert into DataSummary(
SummaryOrder,
SummaryKey,
SummaryLabel,
SummaryValue,
UnformattedNumeric,
UnformattedDatetime
)
values (
1,
'InfoSummary',
'About',
'Some interesting description of your dataset can be written here.',
null,
null
);
-- The following calculates the number of accounts in the data
insert into DataSummary(
SummaryOrder,
SummaryKey,
SummaryLabel,
SummaryValue,
UnformattedNumeric,
UnformattedDatetime
)
values (
2,
'NumAccounts',
'Accounts',
cast((select count(*) from EntitySummary) as varchar),
(select count(*) from EntitySummary),
null
);
-- The following calculates the number of transactions in the data
insert into DataSummary(
SummaryOrder,
SummaryKey,
SummaryLabel,
SummaryValue,
UnformattedNumeric,
UnformattedDatetime
)
values (
3,
'NumLinks',
'Transactions',
cast((select count(*) from YOUR_RAW_DATA) as varchar),
(select count(*) from YOUR_RAW_DATA),
null
);
-- The following calculates the earliest transaction in the data
insert into DataSummary(
SummaryOrder,
SummaryKey,
SummaryLabel,
SummaryValue,
UnformattedNumeric,
UnformattedDatetime
)
values (
4,
'StartDate',
'Earliest Transaction',
(select convert(varchar, min(firstTransaction), 126) from LinkFlow),
null,
(select min(firstTransaction) from LinkFlow)
);
-- The following calculates the latest transaction in the data
insert into DataSummary(
SummaryOrder,
SummaryKey,
SummaryLabel,
SummaryValue,
UnformattedNumeric,
UnformattedDatetime
)
values (
5,
'EndDate',
'Latest Transaction',
(select convert(varchar, max(lastTransaction), 126) from LinkFlow),
null,
(select max(lastTransaction) from LinkFlow)
);
-- Other statistics can be entered in a similar fashion.