From 47758e53fe2517aabb3177743c1e1b7a7d9f7d0a Mon Sep 17 00:00:00 2001 From: Axel Mannhardt Date: Wed, 24 Feb 2016 10:30:08 +0100 Subject: [PATCH] switched object code demo to demo task logic --- app/RemoteExecutable.hs | 37 ++++++++++++++++++++++++++++++++++++- etc/config | 7 ++++--- resources/pseudo-db/1 | 20 ++++++++++---------- resources/pseudo-db/2 | 20 ++++++++++---------- resources/pseudo-db/3 | 20 ++++++++++---------- 5 files changed, 70 insertions(+), 34 deletions(-) diff --git a/app/RemoteExecutable.hs b/app/RemoteExecutable.hs index 8763242..a675fd5 100644 --- a/app/RemoteExecutable.hs +++ b/app/RemoteExecutable.hs @@ -1,8 +1,43 @@ +{-# LANGUAGE BangPatterns #-} module RemoteExecutable (remoteExecutable) where +import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as BLC +import Data.List (foldl') +import Data.Maybe import Control.Distributed.Task.Types.TaskTypes remoteExecutable :: Task -remoteExecutable = map $ flip BLC.append $ BLC.pack " appended" +remoteExecutable = calculateRatio +--remoteExecutable = map $ flip BLC.append $ BLC.pack " appended" + +calculateRatio :: [BL.ByteString] -> [BL.ByteString] +calculateRatio = (:[]) . BLC.pack . show . divideRatio . foldl' (flip countHits) (0, 0) . parseEntries + where + divideRatio :: (Int, Int) -> Double + divideRatio (hits, count) = fromIntegral hits / (fromIntegral count) + countHits :: Entry -> (Int, Int) -> (Int, Int) + -- especially hits are important to evaluate strict here to avoid building up of costly to store thunks, containing entries (count is affected to a lesser degree) + countHits e (!hits, !count) = (hits + if isHit e then 1 else 0, count+1) + +isHit :: Entry -> Bool +isHit (_, _, vs) = maybe False notEmpty $ lookup (BLC.pack "searchCrit") vs + where + notEmpty :: BL.ByteString -> Bool + notEmpty = (>0) . (read :: String -> Int) . BLC.unpack + +parseEntries :: [BL.ByteString] -> [Entry] +parseEntries = catMaybes . map parseEntry + +type Entry = (BL.ByteString, BL.ByteString, [(BL.ByteString, BL.ByteString)]) + +--nlrkwldbji|3101692061|xlerb:uubqpnce|searchCrit:0|longerAttr:nspixnozidyqweu|other:lju|otherRandomNam:tndhdno|otherRandomName2:dgkkj|otherRandomName3:yrdwgww|last:xvofbj +parseEntry :: BL.ByteString -> Maybe Entry +parseEntry str = + let cells = BLC.split '|' str + in if length cells < 2 + then Nothing + else Just (cells !! 0, cells !! 1, catMaybes $ map parseValue $ drop 2 cells) + where + parseValue val = let kv = BLC.split ':' val in if length kv /= 2 then Nothing else Just (kv !! 0, kv !! 1) diff --git a/etc/config b/etc/config index 41564f2..89066a1 100644 --- a/etc/config +++ b/etc/config @@ -4,7 +4,8 @@ pseudo-db-path=resources/pseudo-db distribution-strategy=anywhere task-log-file=log/deployed-executable-task.log source-code-distribution-home=src -object-code-path-on-master=.stack-work/dist/i386-linux/Cabal-1.18.1.5/build/example/example-tmp/ -package-db-path=.stack-work/install/i386-linux/lts-2.22/7.8.4/pkgdb/ +object-code-path-on-master=.stack-work/dist/x86_64-linux/Cabal-1.18.1.5/build/example/example-tmp +package-db-path=.stack-work/install/x86_64-linux/lts-2.22/7.8.4/pkgdb object-code-resources-path-src=src -object-code-resources-path-extra=object-code-app \ No newline at end of file +object-code-resources-path-extra=object-code-app +run-label=setup-description diff --git a/resources/pseudo-db/1 b/resources/pseudo-db/1 index 378c1e4..419ff25 100644 --- a/resources/pseudo-db/1 +++ b/resources/pseudo-db/1 @@ -1,10 +1,10 @@ -brute -bacteria -phantom -fork -collection -hoist -closeup -decadence -concrete -horses +xuvjyjsxie|5502706229|xlerb:hcdguqkulk|searchCrit:2|longerAttr:jxsvsinotqgwlmeg|other:ydsfftmn|otherRandomName:nbw|otherRandomName2:jayweohyff|otherRandomName3:orjm|last:tja +ltbxziugjw|5228796119|xlerb:inythxxg|searchCrit:0|longerAttr:bzbghjggwdozajermfj|other:dmae|otherRandomName:xybbhfvsc|otherRandomName2:|otherRandomName3:iqiallzrju|last:acneag +lgtueiqldw|4347259115|xlerb:nreellfe|searchCrit:1|longerAttr:supdkogzezjrpxvuidbo|other:n|otherRandomName:dytyzh|otherRandomName2:wmjpdfd|otherRandomName3:qyb|last:dgvvo +oknypwvkva|5588701416|xlerb:bblecxobk|searchCrit:0|longerAttr:hfoguxhxtcmwrhu|other:pfbzt|otherRandomName:sw|otherRandomName2:|otherRandomName3:|last:zfhxck +fiminvsiqi|2081652142|xlerb:xvmlna|searchCrit:1|longerAttr:uzmwwvfmoiwhstyoxyj|other:bqgni|otherRandomName:pc|otherRandomName2:zzju|otherRandomName3:uyl|last:tpna +pmjndsrqpi|4537645139|xlerb:gvrwjkt|searchCrit:0|longerAttr:sdaknfftahucozxhcf|other:g|otherRandomName:cfki|otherRandomName2:y|otherRandomName3:mxt|last:dyj +yauahqkhts|7627055310|xlerb:nqjafsu|searchCrit:2|longerAttr:wmowebnjwoqwoptd|other:upxyc|otherRandomName:hrrdlxn|otherRandomName2:|otherRandomName3:dyupftgpoe|last:ipfi +cohuvousec|7101741810|xlerb:bagprate|searchCrit:0|longerAttr:ojtuckenyemeithbzzgk|other:gral|otherRandomName:tkrdajqsf|otherRandomName2:rvmvxpckyo|otherRandomName3:q|last:jvdzs +kqonjineta|5342486512|xlerb:zkyeeu|searchCrit:0|longerAttr:kifqtywooewjzlvpqie|other:|otherRandomName:kvpakhyaw|otherRandomName2:davmyyg|otherRandomName3:dmn|last:pwcqg +aqbvdaxwtg|6546664928|xlerb:vjavsfrm|searchCrit:0|longerAttr:ocghnvxqawomrhwzfu|other:ojhvjih|otherRandomName:inzdim|otherRandomName2:llrexq|otherRandomName3:a|last:ipttex diff --git a/resources/pseudo-db/2 b/resources/pseudo-db/2 index 9d6110c..631c243 100644 --- a/resources/pseudo-db/2 +++ b/resources/pseudo-db/2 @@ -1,10 +1,10 @@ -perfect -carnal -fierce -curiosities -bewitching -fallout -abducted -moonbeam -daughter -amnesia +nshusllhaq|8095075735|xlerb:ukudxlzlvn|searchCrit:2|longerAttr:vsgtsxxgxgqhcoyzon|other:epphr|otherRandomName:jebwau|otherRandomName2:ympvvhuivh|otherRandomName3:xjgvyazc|last:sgy +zrbiyecvef|6816064719|xlerb:drhxpxa|searchCrit:0|longerAttr:ehqphdrwvhipcsa|other:zvrukraqj|otherRandomName:yk|otherRandomName2:mvbpe|otherRandomName3:rdtvtd|last:ywzr +reyypommgw|2142463253|xlerb:rywmemprh|searchCrit:1|longerAttr:vehakwacubytaymeyc|other:oa|otherRandomName:amjdau|otherRandomName2:vxmlzhtuv|otherRandomName3:wnkrmgjfd|last:aucll +arhoxdtjyj|6852181259|xlerb:zlyyutstvn|searchCrit:1|longerAttr:dchwhoioqeiipxtkagwj|other:syvrsedzm|otherRandomName:yuasm|otherRandomName2:eikgwszfk|otherRandomName3:dmxfwm|last:sdivmx +amcyvxxzif|5803235766|xlerb:auhdomir|searchCrit:2|longerAttr:jrpbtaewhvoynezvtm|other:zfljki|otherRandomName:fhteisoqa|otherRandomName2:bac|otherRandomName3:qojeqjfqw|last:gqotj +uzkolggtep|2306490264|xlerb:uxmhirdu|searchCrit:1|longerAttr:yrntriucfwrkaezfjwuz|other:wmygltvjx|otherRandomName:jxedro|otherRandomName2:|otherRandomName3:nonclqn|last:unvavd +riyemvnegw|1827566988|xlerb:rwqyompz|searchCrit:0|longerAttr:barilpcqlhrnvjxb|other:b|otherRandomName:hqjklrxw|otherRandomName2:dysjbffw|otherRandomName3:m|last:llfptj +srddvfcgvc|1091751275|xlerb:eojpgpvw|searchCrit:1|longerAttr:tfqrmczynvdurgubkdl|other:m|otherRandomName:qnyx|otherRandomName2:qaqwh|otherRandomName3:ful|last:wogwoy +gpzntyrecl|3200674820|xlerb:rpbgpqyfj|searchCrit:1|longerAttr:xrstqfzuuvzghfgvd|other:yrpbs|otherRandomName:vmim|otherRandomName2:bukswrhnnt|otherRandomName3:lglf|last:yphm +pgyhalzzas|8221442054|xlerb:iavikxnuny|searchCrit:2|longerAttr:ghyjnvdyvbddqjd|other:tnmhwpwba|otherRandomName:xf|otherRandomName2:o|otherRandomName3:to|last:ienry diff --git a/resources/pseudo-db/3 b/resources/pseudo-db/3 index 5dfe82c..8714dde 100644 --- a/resources/pseudo-db/3 +++ b/resources/pseudo-db/3 @@ -1,10 +1,10 @@ -smuggler -fly -morbid -deer -relearn -juvenile -propellant -hoop -popular -ambition +gnzzqdjxkc|8464038088|xlerb:pgxjnc|searchCrit:0|longerAttr:gyyzcgrrohlwkevqelu|other:p|otherRandomName:foipeqp|otherRandomName2:qcmridqq|otherRandomName3:zzm|last:jlze +vfooosnoof|2761622570|xlerb:bdqrva|searchCrit:2|longerAttr:hbdovejdmccmhytns|other:yglyookye|otherRandomName:ybkb|otherRandomName2:q|otherRandomName3:quo|last:jhltkl +vvpwvpkcxr|3518530398|xlerb:hjttjeydfg|searchCrit:1|longerAttr:mumrgqgivuyljexpbax|other:tvvp|otherRandomName:sf|otherRandomName2:hzehvxfush|otherRandomName3:l|last:wdv +ttsswqxdrc|1375474313|xlerb:bapqqd|searchCrit:0|longerAttr:suweuxhkxggrzmbanwa|other:bxedpbaxe|otherRandomName:elhinrr|otherRandomName2:bpndavicyl|otherRandomName3:lanmizwweh|last:orv +gkwbyccgkx|2748894345|xlerb:riwpqmlk|searchCrit:2|longerAttr:lotyqhjakjyjnczpjopn|other:mydvv|otherRandomName:byniglnmh|otherRandomName2:ilhznj|otherRandomName3:dg|last:ulgbsq +douueoqrrq|8868904977|xlerb:ncygmmcaqn|searchCrit:0|longerAttr:qfwsevootwwhporm|other:kk|otherRandomName:zpyzsplpw|otherRandomName2:fokiunyakk|otherRandomName3:vr|last:zlyn +yitlbdyoco|5533117771|xlerb:jzcjqihvx|searchCrit:0|longerAttr:iwmiubggmpbtztkbsys|other:xphotbqz|otherRandomName:zsnvib|otherRandomName2:|otherRandomName3:qhzmddymiv|last:zgk +uiwswpkytj|3699256618|xlerb:bjijjgrcy|searchCrit:0|longerAttr:mzaagwnzuberpfitfs|other:|otherRandomName:fd|otherRandomName2:|otherRandomName3:jvcqkex|last:xduxh +ncnpmsykpb|8135511703|xlerb:jalrdfgal|searchCrit:0|longerAttr:rlmstlgbdeuslwbqj|other:rkctvxqyr|otherRandomName:byrk|otherRandomName2:upssjpbs|otherRandomName3:cm|last:vwidln +pqvpxpbctc|5792918988|xlerb:vwupcwlq|searchCrit:1|longerAttr:kgywmywmcmauauvwsu|other:|otherRandomName:vjpxs|otherRandomName2:wlqbs|otherRandomName3:|last:oqcew