Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created September 25, 2013 17:08
Show Gist options
  • Select an option

  • Save aamedina/6702775 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/6702775 to your computer and use it in GitHub Desktop.
(def campaigns @campaign-agent)
;; after being deref'd it's just a normal persistent data structure! The power of functional programming at our fingertips!
(def names (project campaigns [:name]))
#{{:name "Calling Max Steel fans_KW in Timeline Mobile"} {:name "Calling Max Steel \
fans"} {:name "First Promoted Account campaign"} {:name "Meet Max Steel_#myhero"} {\
:name "You and Your Child_#myhero"} {:name "First Promoted Tweets campaign"} {:name\
"You and Your Child_ DJ Cole"} {:name "You and Your Child_#myhero Search KW"} {:na\
me "Calling Max Steel fans_-KW in Timeline Desktop_Media Targets"} {:name "Calling \
Max Steel fans_-KW in Timeline Mobile_Media Targets"} {:name "You and Your Child_#m\
yhero v2"} {:name "You & Your Child_Fans of Mattel"} {:name "You & Your Child_Inter\
est v2"} {:name "You & Your Child_Interest"} {:name "Test"} {:name "Meet Max Steel"\
} {:name "Calling Max Steel fans_KW in Timeline Desktop"}}
(sort names)
({:name "Calling Max Steel fans"} {:name "Calling Max Steel fans_KW in Timeline Des\
ktop"} {:name "Calling Max Steel fans_KW in Timeline Mobile"} {:name "Calling Max S\
teel fans_-KW in Timeline Desktop_Media Targets"} {:name "Calling Max Steel fans_-K\
W in Timeline Mobile_Media Targets"} {:name "First Promoted Account campaign"} {:na\
me "First Promoted Tweets campaign"} {:name "Meet Max Steel"} {:name "Meet Max Stee\
l_#myhero"} {:name "Test"} {:name "You & Your Child_Fans of Mattel"} {:name "You & \
Your Child_Interest v2"} {:name "You & Your Child_Interest"} {:name "You and Your C\
hild_ DJ Cole"} {:name "You and Your Child_#myhero Search KW"} {:name "You and Your\
Child_#myhero v2"} {:name "You and Your Child_#myhero"})
(sort-by :start-time campaigns)
;; this sorts all of the campaigns by any key! in this case start time. ommitting results for space lol, it's huge
;; but here's the times themselves
(sort-by :start-time (project campaigns [:start-time]))
({:start-time "2013-03-11T18:09:59Z"} {:start-time "2013-08-12T22:02:00Z"} {:start-\
time "2013-08-13T01:16:00Z"} {:start-time "2013-08-13T17:12:00Z"} {:start-time "201\
3-08-13T19:41:00Z"} {:start-time "2013-08-13T21:40:00Z"} {:start-time "2013-08-13T2\
1:41:00Z"} {:start-time "2013-08-13T21:48:00Z"} {:start-time "2013-08-13T22:06:00Z"\
} {:start-time "2013-08-13T23:15:00Z"} {:start-time "2013-08-14T08:00:00Z"} {:start\
-time "2013-08-14T18:07:00Z"})
(defn avg-daily-budget
[campaigns]
(->> (project campaigns [:daily-budget-amount-local-micro])
(map vals)
(map first)
(reduce +)
(/ (count campaigns)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment