Пример #1
0
import ECA_parser
from datetime import tzinfo, timedelta, date, datetime
import fm

def init(arg):
	pass

# incomplete, which functions do we need here 

datetime_functions = {
	"date" : ( 3, fm.fcall3(datetime.date)),
	"datetime" : ( 6, fm.fcall6(datetime.date)),
	"today" : ( 1, fm.fcall1(datetime.today))
}

ECA_parser.functions.update( datetime_functions )
Пример #2
0
	del ECA_parser.tmpvar[cname]
	return result

def forall(cname, lambda_collection, lambda_result):
	return lambda event: [_bind_and_compute(cname,v,lambda_result,event) for v in lambda_collection(event)]

def json_serialize(json):
	# perhaps a bit clumsy?
	return str(json).replace('\'','\"')

def json2objects(data):
	try:
		return json.loads(data)
	except Exception as e:
		# print("WARNING: no json: "+str(e))
		return None

builtin_functions = {
	"json_serialize" : ( 1, fm.fcall1(json_serialize) ),
	"python" : ( 1, fm.fcall1(run_python)),
	"import" : ( 1, fm.fcall1(run_import)),
	"debug_publish" : ( 1, fm.fcall1(debug_publish)),
	"int" : ( 1, fm.fcall1(int)),
	"float" : ( 1, fm.fcall1(float)),
	# "long" : ( 1, fm.fcall1(long)), INCOMPLETE
	"str" : ( 1, fm.fcall1(str)),
	"print" : ( 1, fm.fcall1(print))
}

ECA_parser.functions.update( builtin_functions )
Пример #3
0
        buildinfo: string to send to client, the idea is that this string
            identifies the build (e.g., in the form of a version number).

    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)),
}
Пример #4
0
        buildinfo: string to send to client, the idea is that this string
            identifies the build (e.g., in the form of a version number).

    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)),
    "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)),
Пример #5
0
# haalt de punctuatie uit een woord. Dit zat deels al in de ECA-code, maar zorgt er nu ook voor dat bata4life, @bata4life en #bata4life allemaal als bata4life
# gelezen kunnen worden. Dit is het verschil tussen een woord een of drie keer in de vereiste woorden zetten.
def expunct(s):
	exclude = set(string.punctuation)
	s = ''.join(ch for ch in s if ch not in exclude)
	return s

# Kijkt of het eerste woord 'RT is. Zoja: return True want dan is het een retweet.
def isRT(text):
	return text.split(' ', 1)[0] == "RT"

# zelfde als getwords, filterd echter alle woorden/nummers, waarachter 'euro' staat (index+1 = 'euro')
def getnumbers(text):
	text = ''.join(ch for ch in text.lower() if ch not in punctuation) 
	words = text.split()
	counts = Counter(words)
	keys = list(counts.keys())
	for index, key in enumerate(words):
		if(index+1) < len(words):
			if not (words[index+1]).endswith('euro'):
				del counts[key]
	return [ v for v in counts]

addmodules_functions = {
	"expunct" : ( 1, fm.fcall1(expunct)),
	"isRT" : ( 1, fm.fcall1(isRT)),
	"getnumbers" : ( 1, fm.fcall1(getnumbers)),
}

ECA_parser.functions.update( addmodules_functions )
Пример #6
0
# events = { 'bar' }

def init(arg):
	pass

def csv_read_kv_dict(csvname,kidx,vidx):
    with open(csvname,mode='r') as infile:
       reader = csv.reader(infile)
       retdict = {}
       for rows in reader:
            k = rows[kidx]
            v = rows[vidx]
            retdict[k] = v
       return retdict

standard_functions = {
	"csv_read_kv_dict" : ( 3, fm.fcall3(csv_read_kv_dict)),
	#
	"slice" : ( 3, (lambda input: lambda event: (tuple(input[1](event))[0])[(input[1](event)[1]):(input[1](event)[2])])),
	"hslice" : ( 2, (lambda input: lambda event: (tuple(input[1](event))[0])[:(input[1](event)[1])])),
	"tslice" : ( 2, (lambda input: lambda event: (tuple(input[1](event))[0])[(input[1](event)[1]):])),
	"substring" : ( 3, (lambda input: lambda event: (tuple(input[1](event))[0])[(input[1](event)[1]):(input[1](event)[2])])),
	#
	"len" : ( 1, fm.fcall1(len))
}



ECA_parser.functions.update( standard_functions )
Пример #7
0
        for v in lambda_collection(event)
    ]


def json_serialize(json):
    # perhaps a bit clumsy?
    return str(json).replace('\'', '\"')


def json2objects(data):
    try:
        return json.loads(data)
    except Exception as e:
        # print("WARNING: no json: "+str(e))
        return None


builtin_functions = {
    "json_serialize": (1, fm.fcall1(json_serialize)),
    "python": (1, fm.fcall1(run_python)),
    "import": (1, fm.fcall1(run_import)),
    "debug_publish": (1, fm.fcall1(debug_publish)),
    "int": (1, fm.fcall1(int)),
    "float": (1, fm.fcall1(float)),
    # "long" : ( 1, fm.fcall1(long)), INCOMPLETE
    "str": (1, fm.fcall1(str)),
    "print": (1, fm.fcall1(print))
}

ECA_parser.functions.update(builtin_functions)
Пример #8
0
        # print(res)
        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!'
Пример #9
0
		num_keys.append(int(key))
	#for value in values:
		#num_values.append(int(value))
	for key in num_keys:
		final[key] = values[i]
		i += 1;
	return final

def import_csv(csvname,kidx,vidx):
    with codecs.open(csvname,mode='r',encoding='utf-8-sig') as infile:
       reader = csv.reader(infile)
       retdict = {}
       for rows in reader:
            k = rows[kidx]
            v = rows[vidx]
            retdict[k] = v
       return retdict

def parseHelper(csvname,kidx,vidx):
	tweets = import_csv(csvname,kidx,vidx)
	parsed = tweets #parseList(tweets)
	return parsed

addmodules_functions = {
	"parseList" : ( 1, fm.fcall1(parseList)),
	"import_csv" : ( 3, fm.fcall3(import_csv)),
	"parseHelper" : ( 3, fm.fcall3(parseHelper))
}

ECA_parser.functions.update( addmodules_functions )
Пример #10
0
	pass

#Gegeven een tweet object geeft het de 'media_url' terug indien deze aanwezig was in het json object van de tweet
def getmediaurl(tweet):
	url = ''
	try:
		j = tweet.data['json']
		url = json.loads(j)['entities']['media'][0]['media_url']
	except KeyError:
		pass
	
	return url

#Gegeven een tweet object geeft het de waarde van 'retweeted' terug uit het json object
def isretweeted(tweet):
	retweet = False
	try:
		j = tweet.data['json']
		retweet = json.loads(j)['retweeted']
	except KeyError:
		pass
	
	return retweet


parse_json_functions = {
	"getmediaurl": (1, fm.fcall1(getmediaurl)),
	"isretweeted": (1, fm.fcall1(isretweeted))
}

ECA_parser.functions.update( parse_json_functions )
Пример #11
0
import fm

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)),
Пример #12
0
import ECA_parser
import fm

def init(arg):
	pass

#Importeert de python module waarvan de naam is gegeven
def module(name):
	return __import__(name)

ECA_parser.functions.update( { "module": (1, fm.fcall1(module)) } )
Пример #13
0

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)),
Пример #14
0
			tdict['weight'] = int(item[1]*self.max_words)
			res.append(tdict)
		# print(res)
		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.')