return False def relevant_tweets(tweet, timestamp): global tweet_container global timeDiff elements = [] result = [] tweet_container.append((timestamp, tweet)) for i in range(len(tweet_container)-1, 0, -1): if tweet_container[i][0] < timestamp - timeDiff: elements = tweet_container[i+1:] break if len(tweet_container) <= 1 or i == 0: elements = tweet_container for i in elements: result.append(i[1]) return result check_functions = { "contains_text" : ( 2, fm.fcall2(contains_text)), "relevant_tweets" : ( 2, fm.fcall2(relevant_tweets)) } ECA_parser.functions.update( check_functions )
import ECA_parser import fm def init(arg): pass def contains_text(text, list): for s in list: if s in text: return True return False check_functions = { "contains_text" : ( 2, fm.fcall2(contains_text)) } ECA_parser.functions.update( check_functions )
Returns: A dict with two members ("event" and "data"), with the value of "data" a JSON serialization of the arguments. This is the format expected by SseHTTPRequestHandler. """ return _encode({"event": "buildInfo", "data": [_serialize(buildinfo)]}) # IMPORTANT: any function which may be used in the ECA rule file must be defined # in he action_function dict action_functions = { # "add_point" : ( 3, lambda input: lambda event: add_point(tuple(input[1](event))[0],tuple(input[1](event))[1],tuple(input[1](event))[2])), "update_gadget" : ( 1, fm.fcall1(update_gadget)), "add_point" : ( 3, fm.fcall3(add_point)), "append_point" : (3, fm.fcall3(append_point)), "message" : ( 1, fm.fcall1(message)), "create_alert_gadget" : ( 3, fm.fcall3(create_alert_gadget)), "alert" : ( 2, fm.fcall2(alert)), "create_general_chart" : ( 4, fm.fcall4(create_general_chart)), "create_maps_gadget" : ( 4, fm.fcall4(create_maps_gadget)), "add_maps_marker" : ( 4, fm.fcall4(add_maps_marker)), "create_tweetlist_gadget" : ( 4, fm.fcall4(create_tweetlist_gadget)), "add_tweetlist_tweet" : ( 2, fm.fcall2(add_tweetlist_tweet)), "create_wordcloud_gadget" : ( 4, fm.fcall4(create_wordcloud_gadget)), "send_buildinfo" : ( 1, fm.fcall1(send_buildinfo)), "update_wordcloud_gadget" : ( 2, fm.fcall2(update_wordcloud_gadget)), } if __name__ == '__main__': pass
import actions import ECA_parser import fm def init(arg): pass #Update een thermometer gadget, waarvan de id gegeven is, met een nieuwe splitwaarde. def update_thermometer(gadget_id, split): return actions.update_thermometer(gadget_id, split) ECA_parser.functions.update({ "updateThermometer": (2, fm.fcall2(update_thermometer)) })
import actions import ECA_parser import fm def init(arg): pass #Stuurt een nieuwe source url van een plaatje naar een image gadget, waarvan de id gegeven is. def update_image(gadget_id, src): print("Image update!") return actions.update_image(gadget_id, src) ECA_parser.functions.update({ "updateImage": (2, fm.fcall2(update_image)) })
import ECA_parser import fm def init(arg): pass #Gegeven een dictionary en een onderwaardegrens geeft het een dictionary terug met alleen de elementen waarvan de value groter was dan de gegeven waarde def filter_notgreater(dict, value): return { k: v for k, v in dict.items() if v > value } ECA_parser.functions.update( { "filter_notgreater": (2, fm.fcall2(filter_notgreater)) } )
""" return _encode({"event": "buildInfo", "data": [_serialize(buildinfo)]}) # IMPORTANT: any function which may be used in the ECA rule file must be defined # in he action_function dict action_functions = { # "add_point" : ( 3, lambda input: lambda event: add_point(tuple(input[1](event))[0],tuple(input[1](event))[1],tuple(input[1](event))[2])), "update_gadget": (1, fm.fcall1(update_gadget)), "add_point": (3, fm.fcall3(add_point)), "append_point": (3, fm.fcall3(append_point)), "line_add_point": (4, fm.fcall4(line_add_point)), "line_append_point": (4, fm.fcall4(line_append_point)), "bar_update": (4, fm.fcall4(bar_update)), "pie_update": (4, fm.fcall4(pie_update)), "message": (1, fm.fcall1(message)), "create_alert_gadget": (3, fm.fcall3(create_alert_gadget)), "alert": (2, fm.fcall2(alert)), "create_general_chart": (4, fm.fcall4(create_general_chart)), "create_maps_gadget": (4, fm.fcall4(create_maps_gadget)), "add_maps_marker": (4, fm.fcall4(add_maps_marker)), "create_tweetlist_gadget": (4, fm.fcall4(create_tweetlist_gadget)), "add_tweetlist_tweet": (2, fm.fcall2(add_tweetlist_tweet)), "create_wordcloud_gadget": (4, fm.fcall4(create_wordcloud_gadget)), "send_buildinfo": (1, fm.fcall1(send_buildinfo)), "update_wordcloud_gadget": (2, fm.fcall2(update_wordcloud_gadget)), } if __name__ == '__main__': pass
# IMPORTANT: any function which may be used in the ECA rule file must be defined # in he action_function dict action_functions = { # "add_point" : ( 3, lambda input: lambda event: add_point(tuple(input[1](event))[0],tuple(input[1](event))[1],tuple(input[1](event))[2])), "update_gadget": (1, fm.fcall1(update_gadget)), "add_point": (3, fm.fcall3(add_point)), "append_point": (3, fm.fcall3(append_point)), "line_add_point": (4, fm.fcall4(line_add_point)), "line_append_point": (4, fm.fcall4(line_append_point)), "bar_update": (4, fm.fcall4(bar_update)), "pie_update": (4, fm.fcall4(pie_update)), "message": (1, fm.fcall1(message)), "create_alert_gadget": (3, fm.fcall3(create_alert_gadget)), "create_thermometer_gadget": (3, fm.fcall3(create_thermometer_gadget)), "update_thermometer": (2, fm.fcall2(update_thermometer)), "create_image_gadget": (3, fm.fcall3(create_image_gadget)), "update_image": (2, fm.fcall2(update_image)), "alert": (2, fm.fcall2(alert)), "create_general_chart": (4, fm.fcall4(create_general_chart)), "create_maps_gadget": (4, fm.fcall4(create_maps_gadget)), "add_maps_marker": (4, fm.fcall4(add_maps_marker)), "create_tweetlist_gadget": (4, fm.fcall4(create_tweetlist_gadget)), "add_tweetlist_tweet": (2, fm.fcall2(add_tweetlist_tweet)), "create_wordcloud_gadget": (4, fm.fcall4(create_wordcloud_gadget)), "send_buildinfo": (1, fm.fcall1(send_buildinfo)), "update_wordcloud_gadget": (2, fm.fcall2(update_wordcloud_gadget)), } if __name__ == "__main__": pass
tdict['text'] = item[0] tdict['weight'] = int(item[1] * self.max_words) res.append(tdict) return res def createWordcloud(max_words): return Wordcloud(int(max_words)) wordcloud_functions = { "createWordcloud": (1, fm.fcall1(createWordcloud)), "getwords": (1, fm.fcall1(getwords)), "stopwords": (0, fm.fcall0(stopwords)), "addText": (2, fm.mcall2(Wordcloud.addText)), "update_wordcloud": (2, fm.fcall2(update_wordcloud)), "getWordWeights": (1, fm.mcall1(Wordcloud.getWordWeights)), } ECA_parser.functions.update(wordcloud_functions) # Test function. if __name__ == '__main__': print("#!TWORDCLOUD") wc = createWordcloud(15) wc.addText( '@vessie @Tapz @Scarbir Ik ben in Enschede zaterdag! Batavierenrace. Veel plezier!' ) wc.addText( 'Ik heb dit weekend bijna 10km hardgelopen, dus vind eigenlijk wel dat ik volgend weekend naar het feestje vd #batavierenrace mag.' )
def init(arg): pass def pi(): return math.pi def e(): return math.e def minus(arg): return - ( arg ) math_functions = { "minus" : ( 1, fm.fcall1(minus)), "ceil" : ( 1, fm.fcall1(math.ceil)), "copysign" : ( 2, fm.fcall2(math.copysign)), "fabs" : ( 1, fm.fcall1(math.fabs)), "factorial" : ( 1, fm.fcall1(math.factorial)), "floor" : ( 1, fm.fcall1(math.floor)), "fmod" : ( 1, fm.fcall1(math.fmod)), "frexp" : ( 1, fm.fcall1(math.frexp)), "fsum" : ( 1, fm.fcall1(math.fsum)), "isinf" : ( 1, fm.fcall1(math.isinf)), "isnan" : ( 1, fm.fcall1(math.isnan)), "ldexp" : ( 2, fm.fcall2(math.ldexp)), "modf" : ( 1, fm.fcall1(math.modf)), "trunc" : ( 1, fm.fcall1(math.trunc)), "exp" : ( 1, fm.fcall1(math.exp)), "expm1" : ( 1, fm.fcall1(math.expm1)), "log" : ( 2, fm.fcall2(math.log)), "log1p" : ( 1, fm.fcall1(math.log1p)),
def pi(): return math.pi def e(): return math.e def minus(arg): return -(arg) math_functions = { "minus": (1, fm.fcall1(minus)), "ceil": (1, fm.fcall1(math.ceil)), "copysign": (2, fm.fcall2(math.copysign)), "fabs": (1, fm.fcall1(math.fabs)), "factorial": (1, fm.fcall1(math.factorial)), "floor": (1, fm.fcall1(math.floor)), "fmod": (1, fm.fcall1(math.fmod)), "frexp": (1, fm.fcall1(math.frexp)), "fsum": (1, fm.fcall1(math.fsum)), "isinf": (1, fm.fcall1(math.isinf)), "isnan": (1, fm.fcall1(math.isnan)), "ldexp": (2, fm.fcall2(math.ldexp)), "modf": (1, fm.fcall1(math.modf)), "trunc": (1, fm.fcall1(math.trunc)), "exp": (1, fm.fcall1(math.exp)), "expm1": (1, fm.fcall1(math.expm1)), "log": (2, fm.fcall2(math.log)), "log1p": (1, fm.fcall1(math.log1p)),
res = [] for item in final: tdict = {} tdict['text'] = item[0] tdict['weight'] = int(item[1]*self.max_words) res.append(tdict) return res def createWordcloud(max_words): return Wordcloud(int(max_words)) wordcloud_functions = { "createWordcloud" : ( 1, fm.fcall1(createWordcloud)), "getwords" : ( 1, fm.fcall1(getwords)), "stopwords" : ( 0, fm.fcall0(stopwords)), "addText" : ( 2, fm.mcall2(Wordcloud.addText)), "update_wordcloud" : ( 2, fm.fcall2(update_wordcloud)), "getWordWeights" : ( 1, fm.mcall1(Wordcloud.getWordWeights)), } ECA_parser.functions.update( wordcloud_functions ) # Test function. if __name__ == '__main__': print("#!TWORDCLOUD") wc = createWordcloud(15) wc.addText('@vessie @Tapz @Scarbir Ik ben in Enschede zaterdag! Batavierenrace. Veel plezier!') wc.addText('Ik heb dit weekend bijna 10km hardgelopen, dus vind eigenlijk wel dat ik volgend weekend naar het feestje vd #batavierenrace mag.') wc.addText('Bataradio doet live verslag Batavierenrace http://t.co/6FVfQE') wc.getWordWeights()