a SVa@sddlZddlZddlZddlTddZddZdddZdd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZdS)N)*cCs&||vr|||7<n|||<dSNZ dictionarykeyvaluerr`/Users/lrettenm/Projects/AB3/aws-serverless-realtime-aggregation/Frontend/../Common/functions.pydict_entry_addsr cCs ||vs|||kr|||<dSrrrrrrdict_entry_minsr cCspt|dd}|s@tdd|dd|d|dd n,tdd|dd|d ||dd dS) Nz [# 2z] {:.1f}% completed.)endz4] {:.1f}% completed. Speed: {:.1f} Messages / Second)intprintformat)ZprogressspeedZ progress_barrrrprint_progress_bar!srFcCs:|r|j|dd}n |j|d}d|vr2|d}nd}|S)NT)KeyConsistentRead)rZItem)Zget_item)tablekey_nameZstrong_consistencyresponseitemrrr get_item_ddb1s  rcCshd}t}d}d}d}|sd|r&||d<|jfi|}|dd}|du}|dg}|t|7}q|S)NrFZExclusiveStartKeyZLastEvaluatedKeyItems)dictscangetlen)rZ item_countZ scan_argsdoneZ start_keyiritemsrrr count_itemsBs  r&cCstdtdtd}|S)Nd)randomrandintZMIN_VALUE_OF_RISKZMAX_VALUE_OF_RISK)rrrr random_value]sr*cCs*t}tD]\}}t|||<q|Sr)rZHIERARCHY_DEFINITIONr%r(choice)Z hierarchykvrrrrandom_hierarchybsr.cCs4d}d}|D]"}|rd}n|d7}|||7}q |S)NrTF:r)Zhierarchy_dictionaryZaggregation_hierarchyZ type_stringstartlevelrrrhierarchy_to_stringisr2csntdd|D}t|ddD]Ffdd|D}|D]&}|d|d}t||||q@q"|S)NcSsg|]}|dqSr/count.0rrrr yz(aggregate_along_tree..rcsg|]}|dkr|qSr3r4r6depthrrr8}r9r/)maxkeysrangerfindr )dataZaggregation_depthchildrenchildparentrr;raggregate_along_treevsrEc Cst}|D]}d|tvrq |td}t|td}t|td}t|td}t|t }t |||t |t |t |t |d|tvr|td}t|td} t|td} t| t } t || | t |tdq |r|t |t<|S)NZNewImageSNZOldImager )r DYNAMO_NAMEjsonloadsHIERARCHY_COLUMN_NAMEfloatVALUE_COLUMN_NAMETIMESTAMP_COLUMN_NAMEr2AGGREGATION_HIERARCHYr TIMESTAMP_GENERATOR_MEANr TIMESTAMP_GENERATOR_FIRSTMESSAGE_COUNT_NAME) recordsdeltarecordnew_dataZ new_hierarchy new_valueZnew_generated_timenew_typeZold_dataZ old_hierarchy old_valueZold_typerrraggregate_over_dynamo_recordss,         rZcCst}|D]t}tt|tdd}|t}|t}|t }t |t }t |||t |t |t|t|t |tdq |r|t |t<|S)NrAzutf-8r )rrIrJbase64 b64decodeZ KINESIS_NAMEdecoderKrMrNr2rOr rPr rQrR)rSrTrUrAZrecord_hierarchyZ record_valueZ record_timeZ record_typerrraggregate_over_kinesis_recordss    r^)N)F)r(rIr[ constantsr r rrr&r*r.r2rErZr^rrrr s   0