<commit_before>
# coding: utf-8


from pyspark import SparkContext, SparkConf
from pyspark.streaming import StreamingContext
from pyspark.sql import SQLContext, Row, SparkSession
from pyspark.sql.types import *
import bus_times


# In[ ]:

def toHalfHourBucket(x):
        hora= (x[2] // (60*60))%24
        minuto= (x[2] //60)%60
        if (minuto < 30):
            minuto=0.0
        else:
            minuto=0.5
        valor= hora+minuto
        x[2]=valor
        return x



def toCSV(x):
    y=str(x[0])
    for i in range(1,len(x)):
       y= y+","+str(x[i]) 
    return y



def streamMainFilter(dstream):
	splitted_ds= dstream.map(lambda x:x.split('\t'))	
	discard_headers=splitted_ds.filter(lambda x : x[0]!="latitude")	
	format_time=discard_headers.map(lambda x: bus_times.forTim(x))
	hh_bucket=format_time.map(lambda x: toHalfHourBucket(x))
	selected_ds= hh_bucket.map(lambda x:(x[0],x[1],x[2],x[3],x[5],x[7],x[10]))

	return selected_ds

    
##########################################################################
#conf = SparkConf().setMaster("spark://King:7077").setAppName("batch_Main")
conf = SparkConf().setAppName("stream_Main")

sc = SparkContext(conf = conf)
sc.addPyFile("/home/bdata/sparkPrograms/BD-Traffic/bus_times.py")

ssc = StreamingContext(sc, 1)
<commit_msg>changed user from gusseppe to Piero T again<commit_after>
# coding: utf-8


from pyspark import SparkContext, SparkConf
from pyspark.streaming import StreamingContext
from pyspark.sql import SQLContext, Row, SparkSession
from pyspark.sql.types import *
import bus_times


# In[ ]:

def toHalfHourBucket(x):
        hora= (x[2] // (60*60))%24
        minuto= (x[2] //60)%60
        if (minuto < 30):
            minuto=0.0
        else:
            minuto=0.5
        valor= hora+minuto
        x[2]=valor
        return x



#def toCSV(x):
#    y=str(x[0])
#    for i in range(1,len(x)):
#       y= y+","+str(x[i]) 
#    return y



def streamMainFilter(dstream):
	splitted_ds= dstream.map(lambda x:x.split('\t'))	
	discard_headers=splitted_ds.filter(lambda x : x[0]!="latitude")	
	format_time=discard_headers.map(lambda x: bus_times.forTim(x))
	hh_bucket=format_time.map(lambda x: toHalfHourBucket(x))
	selected_ds= hh_bucket.map(lambda x:(x[0],x[1],x[2],x[3],x[5],x[7],x[10]))

	return selected_ds

    
##########################################################################
#conf = SparkConf().setMaster("spark://King:7077").setAppName("batch_Main")
conf = SparkConf().setAppName("stream_Main")

sc = SparkContext(conf = conf)
sc.addPyFile("/home/bdata/sparkPrograms/BD-Traffic/bus_times.py")

ssc = StreamingContext(sc, 1)

{'fraction_non_alphanumeric': 0.20365435858393605, 'fraction_numerical': 0.027407689379520365, 'mean_word_length': 4.0344827586206895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7341175', 'n_tokens_mistral': 1035, 'n_tokens_neox': 971, 'n_words': 175}