예제 #1
0
def gen_csv(id):
    #
    # result [ (word, [ link, { occurence: count } ]) ]
    #
    if not 'authorized' in session:
        return redirect('/')
    try:
        l = tasks[id].result
        start = tasks[id].starttime
        stop = tasks[id].stoptime
    except IndexError:
        flash('Ошибка создания CSV')
        return redirect('/')
    csv = ''
    csv += 'Время начала;%s\nВремя окончания;%s\n\n' % (start, stop)
    for result in l:
        csv += '\n%s;;\n' % result[0].strip()
        if len(result[1]) > 0:
            for link in result[1]:
                if len(link[1]) > 0:
                    csv += ';%s;\n' % (link[0].strip())
                    for occurence in link[1]:
                        csv += ';;%s;%i\n' % (occurence, link[1][occurence])
        else:
            csv += ';Вхождений на сайте не найдено!;\n'
    return Response(
        csv.encode('cp1251', errors='replace'),
        mimetype="text/csv",
        headers={"Content-disposition": "attachment; filename=report.csv"})
    def _iterate(self) -> Iterator[bytes]:
        """
        Execute a query against a postgres DB
        using SQLAlchemy

        See http://docs.sqlalchemy.org/en/latest/_modules/examples/performance/large_resultsets.html
        for SQLAlchemy docs on querying large data sets
        """
        # Execute the query, creating a DB cursor object
        self._db_cursor = self._db \
            .execution_options(stream_results=True) \
            .execute(sql_text(self._query))

        while True:
            # Fetch 1000 records at a time from the DB
            records = self._db_cursor.fetchmany(1000)

            # If there are no more results, we can stop iterating
            if not records:
                yield b""
                break

            # Format results as a CSV
            csv = to_csv(records)
            yield csv.encode('utf8')
예제 #3
0
    def export_csv(self, request):
        """
        Create a csv file and return it as a HttResponse
        request -- a HttpResponse
        """
        objs = self.model.objects.all().select_related()

        rows = []
        for obj in objs:
            row = []
            row.extend(self._get_instance_values(obj, self.csv_fields))

            rows.append(','.join(row))

        row = []
        [row.append(self._get_model_field(attr)) for attr in self.csv_fields]
        rows.insert(0, ','.join(row))

        csv = '\r\n'.join(rows)
        csv = csv.encode('iso-8859-1')

        response = HttpResponse(csv, mimetype='text/csv')
        response['Content-Disposition'] = 'attachment; filename=%s.csv' % self.csv_filename

        return response
예제 #4
0
def create_download_link(df, title = "Download CSV file", filename = "data.csv"):  
    csv = df.to_csv()
    b64 = base64.b64encode(csv.encode())
    payload = b64.decode()
    html = '<a download="{filename}" href="data:text/csv;base64,{payload}" target="_blank">{title}</a>'
    html = html.format(payload=payload,title=title,filename=filename)
    return HTML(html)
예제 #5
0
 def _create_batch(self, jobid, data):
     """This posts the batch data in CSV format, and return the batch id"""
     csv = utils.make_csv(data)
     payload = csv.encode('utf-8')
     url = self.api.async_url + 'job/' + jobid + '/batch'
     qr = utils.decode_xml(
         self.api.do_post(url, payload, 'text/csv; charset=utf-8'))
     return qr['id']
def get_table_download_link(df, filename='download', message='Download csv result file'):
    """Generates a link allowing the data in a given panda dataframe to be downloaded
    in:  dataframe
    out: href string
    """
    csv = df.to_csv(index=False)
    b64 = base64.b64encode(csv.encode()).decode()  # some strings <-> bytes conversions necessary here
    href = f'<a href="data:file/csv;base64,{b64}" download="{filename}.csv" >{message}</a>'
    return href
def get_table_download_link(dafr):
    """Generates a link allowing the data in a given panda dataframe to be downloaded
    in:  dataframe
    out: href string
    """
    csv = dafr.to_csv(index=False)
    b64 = base64.b64encode(csv.encode()).decode(
    )  # some strings <-> bytes conversions necessary here
    return f'<a href="data:file/csv;base64,{b64}" download="Results.csv">Download Result (CSV)</a>'
예제 #8
0
파일: gavel.py 프로젝트: codebeyond/gavel
def annotator():
    action = request.form['action']
    if action == 'Submit':
        csv = request.form['data']
        data = data_from_csv_string(csv.encode('utf8'))
        for row in data:
            annotator = Annotator(*row)
            db.session.add(annotator)
        db.session.commit()
    elif action == 'Delete':
        id = request.form['annotator_id']
        try:
            db.session.execute(ignore_table.delete(ignore_table.c.annotator_id == id))
            Annotator.query.filter_by(id=id).delete()
            db.session.commit()
        except IntegrityError as e:
            return render_template('error.html', message=str(e))
    return redirect(url_for('admin'))
예제 #9
0
def generate_passengers_list():
    jan_first = datetime.datetime.combine(datetime.date(2012, 1, 1),
                                          default_tz_time_min())
    rides = SharedRide.objects.filter(depart_time__gte=jan_first)

    passengers = []
    for ride in rides:
        if ride.debug:
            continue
        for o in ride.orders.all():
            if o.passenger.create_date > jan_first:
                passengers.append(o.passenger)

    passengers = set(passengers)

    csv = u""
    for p in passengers:
        user = p.user
        csv += u",".join([user.email, user.get_full_name()])
        csv += u"\n"

    send_mail_as_noreply("*****@*****.**",
                         "passengers list",
                         attachments=[("passengers.csv", csv.encode("utf-8"))])
예제 #10
0
edgescoloured = edges.style.background_gradient(cmap='Blues')

#format_dictionary = {
#'Ent. Count (1st URL)':'{:.0f}',
#'Salience (1st URL)':'{:.1%}',
#'Salience Diff':'{:.1%}',
#'Ent. Count (2nd URL)':'{:.0f}',
#'Salience (2nd URL)':'{:.1%}'
#}

st.table(edgescoloured)

try:

    csv = edges.to_csv(index=False)
    b64 = base64.b64encode(csv.encode()).decode()
    #st.markdown('### ** ⬇️ Download the selected table to CSV **')
    st.markdown('### **⬇️ Export CSV file **')
    href = f'<a href="data:file/csv;base64,{b64}" download="filtered_table.csv">Click here to get your prize! 🎉</a>'
    st.markdown(href, unsafe_allow_html=True)

except NameError:
    print('wait')

st.markdown("---")

with st.beta_expander("📝 - To-Do's ⯈", expanded=False):
    st.write("""
	    
st.markdown("•  Currently in Beta - See To-Do's* 📝")
st.markdown("•  StreamSuggets is currently in Beta - See To-Do's 📝")
예제 #11
0
def main():

	menu = ["Team","Lieu d'intérêt", "Evénement", "Produit", "Itinéraire", "Maintenance"]
	choice = st.sidebar.radio("Menu", menu)

	

	if choice == "Team":
		


		image = Image.open('DATAtourisme.png')
		st.image(image, use_column_width = True, output_format = 'PNG')


		st.markdown("<h1 style='text-align: center; font-size:15px; color:#A11F40;'>Qu'est ce que DATAtourisme ?</h1>", unsafe_allow_html=True)   

		st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'></h1>", unsafe_allow_html=True)   
		

		col1, col2, col3 = st.beta_columns((1,13,1))   		
   				
		with col1:
   		   
   		   st.markdown("")

		with col2:
			st.markdown("**DATAtourisme** est un dispositif national visant à **faciliter l’accès aux données publiques d’information touristique** produites à travers les territoires par les offices de tourisme et les comités départements ou régionaux du tourisme. Il se matérialise par une plateforme de collecte, de normalisation et de diffusion de données en open data, directement reliée aux bases de données territoriales, et repose sur l’animation d’une communauté d’utilisateurs. Le dispositif est **copiloté par** la **Direction générale des entreprises** et la **fédération ADN Tourisme**. Les données collectées sont relatives au recensement de l’ensemble des événements et points d’intérêt touristiques de France (musées, monuments, sites naturels, activités, itinéraires, expos et concerts, etc)", unsafe_allow_html=True)   


		with col3:
			st.markdown("")



		st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'></h1>", unsafe_allow_html=True)   


		st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'></h1>", unsafe_allow_html=True)


		st.markdown("<h1 style='text-align: center; font-size:15px; color:#A11F40;'>Qui sommes-nous ?</h1>", unsafe_allow_html=True)   

		st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'></h1>", unsafe_allow_html=True)   
		


		col1, col2, col3 = st.beta_columns((1,13,1))   		
   				
		with col1:
   		   
   		   st.markdown("")

		with col2:
			st.markdown("Dans le cadre de notre formation professionnelle de Data Analyst, **notre équipe** de 5 s'est alliée à **ADN Tourisme** pour proposer un **état des lieux** constamment à jour du **projet DATAtourisme** (qualité, quantité, points d'amélioration), ce qui n'existait pas jusqu'alors. Notre script effectue un **travail important en amont** pour récupérer, nettoyer et constuire la donnée présentée ici.", unsafe_allow_html=True)   

		with col3:
			st.markdown("")   		   



		st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'></h1>", unsafe_allow_html=True)   
		

		col1, col2, col3 = st.beta_columns((3,0.72,3))

		with col1:
			st.markdown("")

		with col2:
			if st.button("Team"):
			   st.balloons()

		with col3:
			st.markdown("")


		st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'></h1>", unsafe_allow_html=True)   
		





#		st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'>Team</h1>", unsafe_allow_html=True)   

		



		col1, col2, col3, col4, col5 = st.beta_columns(5)   		
   				
		with col1:
   		   
   		   st.image("cm1.jpg", use_column_width=True)
   		   st.markdown("""**Carla&#8239;Moreno**""")
   		   st.markdown("""*Scrum Master*""")
   		   st.markdown(link1, unsafe_allow_html=True)

		with col2:
   		   
   		   st.image("cc.jpg", use_column_width=True)
   		   st.markdown("""**Corentin&#8239;Guillo**""")
   		   st.markdown("""*Product Owner*""")
   		   st.markdown(link4, unsafe_allow_html=True)


		with col3:
   		   
   		   st.image("Yvanne.jpg", use_column_width=True)	
   		   st.markdown("""**Yvanne&#8239;Euchin**""")
   		   st.markdown("""*Equipe Tech*""")
   		   st.markdown(link2, unsafe_allow_html=True)



		with col4:
		   st.image("md.jpg", use_column_width=True)
		   st.markdown("""**Michael&#8239;Desforges**""")
		   st.markdown("""*Equipe Tech*""")
		   st.markdown(link, unsafe_allow_html=True)


		with col5:
		   st.image("ab.jpg", use_column_width=True)
		   st.markdown("""**Amar&#8239;Barache**""")
		   st.markdown("""*Equipe Tech*""")
		   st.markdown(link5, unsafe_allow_html=True)



		image = Image.open('WCS.png')
		st.image(image, use_column_width = True, output_format = 'PNG')


		page_bg_img = '''
		<style>
		body {
		background-image: url("https://i.ibb.co/cD9CndX/nuages2.jpg");
		background-size: cover;
		}
		</style>
		'''

		st.markdown(page_bg_img, unsafe_allow_html=True)


	if choice == "Produit":
		data = data1




		image = Image.open('DATAtourisme.png')
		st.image(image, use_column_width = True, output_format = 'PNG')

		st.markdown("<h1 style='text-align:center; font-size:29px; color: #57565B;'>Produit</h1>", unsafe_allow_html=True)




		if st.checkbox('voir dataframe'):
		   st.write(data)
#		   st.write(data.iloc[0:100,:])
		 
				 


		f" POI : **{len(data1.index)}** sur **{len(data1.index)+len(data2.index)+len(data3.index)+len(data4.index)}** au total"

		f" Créateurs de données : **{len(data1.createur_donnée.unique())}**"

		f" Fournisseurs : **{len(data1.fournisseur.unique())}**"

		f" Villes : **{len(data1.ville.unique())}**"

		f" POI avec photo :  **{int(round(data1.photo.sum()/len(data1.photo.index)*100))}%**"


				 

		st.markdown(""" # **Densité de POI** """)

		fig = px.density_mapbox(data, lat='latitude', lon='longitude', radius=4,
                        center={"lat": 46.037763, "lon": 4.4}, zoom=4, color_continuous_midpoint = 5,
                        mapbox_style='carto-positron', color_continuous_scale=['grey','darkgrey','grey','red','red'])
		fig.update_layout(coloraxis_showscale=False,margin=dict( l=0, r=0, b=0, t=0, pad = 4 ))
		fig.update_traces(hoverinfo='skip', hovertemplate=None)
		st.plotly_chart(fig)

		



		st.markdown("""# **Par départements**""")


		fig = px.choropleth_mapbox(data, 
                           geojson=france_regions_geo, 
                           color=data.code_departement.value_counts(),
                           locations=data.code_departement.value_counts().index.tolist(), 
                           featureidkey='properties.code',
                           opacity=1,
                           center={"lat": 46.037763, "lon": 2.062783},
                           mapbox_style="carto-positron", zoom=4)

		fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
		st.plotly_chart(fig)


#		st.markdown(""" # **Répartition des sous-categories** """)


#		x = list(data.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().index[0:17])#.drop("HébergementProduit",axis=0).index[0:17])
#		y=list(data.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().iloc[0:17])#.drop("HébergementProduit",axis=0).iloc[0:17])
#		fig = px.bar(x=x,y=y,color_discrete_sequence =['#A11F40'])
#		fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},showlegend=False,yaxis=dict(title=None), xaxis=dict(title=None,type="category"))
#		st.plotly_chart(fig)



		

#		x = list(data.sous_categorie.str.split(',',expand = True).stack().explode().value_counts().drop("HébergementProduit",axis=0).index)
#		y=list(data.sous_categorie.str.split(',',expand = True).stack().explode().value_counts().drop("HébergementProduit",axis=0))
#		fig = px.bar(x=x,y=y,color_discrete_sequence =['#A11F40'])
#		fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},showlegend=False,yaxis=dict(title=None), xaxis=dict(title=None,type="category"))
#		st.plotly_chart(fig)

		

#		image = Image.open('WCS.png')
#		st.image(image, use_column_width = True, output_format = 'PNG')





	elif choice == "Evénement":
		data = data2



		image = Image.open('DATAtourisme.png')
		st.image(image, use_column_width = True, output_format = 'PNG')

		st.markdown("<h1 style='text-align:center; font-size:29px; color: #57565B;'>Evénement</h1>", unsafe_allow_html=True)



		if st.checkbox('voir dataframe'):
		   st.write(data.iloc[0:100,:])
		 

		f" POI : **{len(data2.index)}** sur **{len(data1.index)+len(data2.index)+len(data3.index)+len(data4.index)}** au total"

		f" Créateurs de données : **{len(data2.createur_donnée.unique())}**"

		f" Fournisseurs : **{len(data2.fournisseur.unique())}**"

		f" Villes : **{len(data2.ville.unique())}**"

		f" POI avec photo :  **{int(round(data2.photo.sum()/len(data2.photo.index)*100))}%**"
			
		

		st.markdown(""" # **Densité de POI** """)

		fig = px.density_mapbox(data, lat='latitude', lon='longitude', radius=4,
                        center={"lat": 46.037763, "lon": 4.4}, zoom=4, color_continuous_midpoint = 5,
                        mapbox_style='carto-positron', color_continuous_scale=['grey','darkgrey','grey','red','red'])
		fig.update_layout(coloraxis_showscale=False,margin=dict( l=0, r=0, b=0, t=0, pad = 4 ))
		fig.update_traces(hoverinfo='skip', hovertemplate=None)
		st.plotly_chart(fig)

		st.markdown("""# **Par départements**""")

		fig = px.choropleth_mapbox(data, 
                           geojson=france_regions_geo, 
                           color=data.code_departement.value_counts(),
                           locations=data.code_departement.value_counts().index.tolist(), 
                           featureidkey='properties.code',
                           opacity=1,
                           center={"lat": 46.037763, "lon": 2.062783},
                           mapbox_style="carto-positron", zoom=4)

		fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
		st.plotly_chart(fig)


#		st.markdown(""" # **Répartition des sous-categories** """)


#		x = list(data.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().index[0:17])
#		y=list(data.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().iloc[0:17])
#		fig = px.bar(x=x,y=y,color_discrete_sequence =['#A11F40'])
#		fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},showlegend=False,yaxis=dict(title=None), xaxis=dict(title=None,type="category"))
#		st.plotly_chart(fig)




#		x = list(data.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().index)
#		y=list(data.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts())
#		fig = px.bar(x=x,y=y,color_discrete_sequence =['#A11F40'])
#		fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},showlegend=False,yaxis=dict(title=None), xaxis=dict(title=None,type="category"))
#		st.plotly_chart(fig)


		

#		image = Image.open('WCS.png')
#		st.image(image, use_column_width = True, output_format = 'PNG')



	elif choice == "Lieu d'intérêt":
		data = data3



		image = Image.open('DATAtourisme.png')
		st.image(image, use_column_width = True, output_format = 'PNG')


		st.markdown("<h1 style='text-align:center; font-size:29px; color: #57565B;'>Lieux d'intérêt</h1>", unsafe_allow_html=True)



		if st.checkbox('voir dataframe'):
		   st.write(data.iloc[0:100,:])
		   
		   
		



		f" POI : **{len(data3.index)}** sur **{len(data1.index)+len(data2.index)+len(data3.index)+len(data4.index)}** au total"

		f" Créateurs de données : **{len(data3.createur_donnée.unique())}**"

		f" Fournisseurs : **{len(data3.fournisseur.unique())}**"

		f" Villes : **{len(data3.ville.unique())}**"

		f" POI avec photo :  **{int(round(data3.photo.sum()/len(data3.photo.index)*100))}%**"

				

		st.markdown(""" # **Densité de POI** """)

		fig = px.density_mapbox(data, lat='latitude', lon='longitude', radius=4,
                        center={"lat": 46.037763, "lon": 4.4}, zoom=4, color_continuous_midpoint = 5,
                        mapbox_style='carto-positron', color_continuous_scale=['grey','darkgrey','grey','red','red'])
		fig.update_layout(coloraxis_showscale=False,margin=dict( l=0, r=0, b=0, t=0, pad = 4 ))
		fig.update_traces(hoverinfo='skip', hovertemplate=None)
		st.plotly_chart(fig)

		st.markdown("""# **Par départements**""")

		fig = px.choropleth_mapbox(data, 
                           geojson=france_regions_geo, 
                           color=data.code_departement.value_counts(),
                           locations=data.code_departement.value_counts().index.tolist(), 
                           featureidkey='properties.code',
                           opacity=1,
                           center={"lat": 46.037763, "lon": 2.062783},
                           mapbox_style="carto-positron", zoom=4)

		fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
		st.plotly_chart(fig)

#		st.markdown(""" # **Répartition des sous-categories** """)

#		x = list(data.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().index[0:17])
#		y=list(data.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().iloc[0:17])
#		fig = px.bar(x=x,y=y,color_discrete_sequence =['#A11F40'])
#		fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},showlegend=False,yaxis=dict(title=None), xaxis=dict(title=None,type="category"))
#		st.plotly_chart(fig)



#		image = Image.open('WCS.png')
#		st.image(image, use_column_width = True, output_format = 'PNG')



	elif choice == "Itinéraire":
		data = data4




		image = Image.open('DATAtourisme.png')
		st.image(image, use_column_width = True, output_format = 'PNG')


		st.markdown("<h1 style='text-align:center; font-size:29px; color: #57565B;'>Itinéraire</h1>", unsafe_allow_html=True)



		if st.checkbox('voir dataframe'):
		   st.write(data.iloc[0:100,:])
		 		   

		f" **POI** : **{len(data4.index)}** sur **{len(data1.index)+len(data2.index)+len(data3.index)+len(data4.index)}** au total"

		f" Créateurs de données : **{len(data4.createur_donnée.unique())}**"

		f" Fournisseurs : **{len(data4.fournisseur.unique())}**"

		f" Villes : **{len(data4.ville.unique())}**"

		f" POI avec photo :  **{int(round(data4.photo.sum()/len(data4.photo.index)*100))}%**"

				 	

		st.markdown(""" # **Densité de POI** """)

		fig = px.density_mapbox(data, lat='latitude', lon='longitude', radius=4,
                        center={"lat": 46.037763, "lon": 4.4}, zoom=4, color_continuous_midpoint = 5,
                        mapbox_style='carto-positron', color_continuous_scale=['grey','darkgrey','grey','red','red'])
		fig.update_layout(coloraxis_showscale=False,margin=dict( l=0, r=0, b=0, t=0, pad = 4 ))
		fig.update_traces(hoverinfo='skip', hovertemplate=None)
		st.plotly_chart(fig)

		st.markdown("""# **Par départements**""")

		fig = px.choropleth_mapbox(data, 
                           geojson=france_regions_geo, 
                           color=data.code_departement.value_counts(),
                           locations=data.code_departement.value_counts().index.tolist(), 
                           featureidkey='properties.code',
                           opacity=1,
                           center={"lat": 46.037763, "lon": 2.062783},
                           mapbox_style="carto-positron", zoom=4)

		fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
		st.plotly_chart(fig)

		
#		x = list(data.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().index[0:17])
#		y=list(data.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().iloc[0:17])
#		fig = px.bar(x=x,y=y,color_discrete_sequence =['#A11F40'])
#		fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},showlegend=False,yaxis=dict(title=None), xaxis=dict(title=None,type="category"))
#		st.plotly_chart(fig)
				

			
#		image = Image.open('WCS.png')
#		st.image(image, use_column_width = True, output_format = 'PNG')

	elif choice == "Maintenance":

		image = Image.open('DATAtourisme.png')
		st.image(image, use_column_width = True, output_format = 'PNG')


		mdp = st.text_input("Mot de passe ?", type="password")


		st.write()
		if mdp == "Les+tour1stes.":
			if st.checkbox('voir dataframe'):
				st.write(data_erreur)
				st.markdown("")
				download = st.button('télécharger')
				if download:
					csv = data_erreur.to_csv(index=False)
					b64 = base64.b64encode(csv.encode()).decode()  
					linko= f'<a href="data:file/csv;base64,{b64}" download="data_erreur.csv">Download csv file</a>'
					st.markdown(linko, unsafe_allow_html=True)
				 	

			f" Départements sans fournisseurs : **{data_erreur[data_erreur.fournisseur.isna()].code_departement.unique()}**"
			f" Départements sans créateur : **{data_erreur[data_erreur.createur_donnée.isna()].code_departement.unique()}**"
			f" Fournisseurs sans région : **{data_erreur[data_erreur.region.isna()].fournisseur.unique()}**"
			st.markdown("")
			st.markdown(""" # **Carte des erreurs latitude & longitude** """)
			st.markdown("")
			st.map(data_erreur_map)

			st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'>Répartition des sous-categories de la categorie Lieu d'intérêt</h1>", unsafe_allow_html=True)
			x = list(data3.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().index[0:17])
			y=list(data3.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().iloc[0:17])
			fig = px.bar(x=x,y=y,color_discrete_sequence =['#A11F40'])
			fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},showlegend=False,yaxis=dict(title=None), xaxis=dict(title=None,type="category"))
			st.plotly_chart(fig)

			st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'>Répartition des sous-categories de la categorie Lieu Evénement</h1>", unsafe_allow_html=True)
			x = list(data2.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().index[0:17])
			y=list(data2.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().iloc[0:17])
			fig = px.bar(x=x,y=y,color_discrete_sequence =['#A11F40'])
			fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},showlegend=False,yaxis=dict(title=None), xaxis=dict(title=None,type="category"))
			st.plotly_chart(fig)

			st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'>Répartition des sous-categories de la categorie Produit</h1>", unsafe_allow_html=True)
			x = list(data1.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().index[0:17])#.drop("HébergementProduit",axis=0).index[0:17])
			y=list(data1.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().iloc[0:17])#.drop("HébergementProduit",axis=0).iloc[0:17])
			fig = px.bar(x=x,y=y,color_discrete_sequence =['#A11F40'])
			fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},showlegend=False,yaxis=dict(title=None), xaxis=dict(title=None,type="category"))
			st.plotly_chart(fig)

			st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'>Répartition des sous-categories de la categorie Itinéraire</h1>", unsafe_allow_html=True)
			x = list(data4.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().index[0:17])
			y=list(data4.sous_categorie.str.split(', ',expand = True).stack().explode().value_counts().iloc[0:17])
			fig = px.bar(x=x,y=y,color_discrete_sequence =['#A11F40'])
			fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},showlegend=False,yaxis=dict(title=None), xaxis=dict(title=None,type="category"))
			st.plotly_chart(fig)
		
		
		
   
		

#		image = Image.open('WCS.png')
#		st.image(image, use_column_width = True, output_format = 'PNG')


				



	else:
		st.subheader("""  """)
예제 #12
0
def get_table_download_link(df):
	csv = data_erreur.to_csv(index=False)
	b64 = base64.b64encode(csv.encode()).decode()  
	href = f'<a href="data:file/csv;base64,{b64}">Download csv file</a>'	
def input_choice_flow():
    input_choices_activities = ["Text", "Upload File"]
    input_choice = st.sidebar.selectbox("Input Choices",
                                        input_choices_activities)
    if input_choice == "Text":
        caching.clear_cache()
        raw_text = st.text_area("Enter Text")
        if st.button("Analyze"):
            result = model_predict(raw_text)
            # st.write('Result: {}'.format(model_predict(raw_text)))
            if result == '[\'positive\']':
                st.info("Result :")
                custom_emoji = ':smile:'
                st.success(
                    emoji.emojize(custom_emoji, use_aliases=True) +
                    ' Positive')
            elif result == '[\'neutral\']':
                st.info("Result :")
                custom_emoji = ':expressionless:'
                st.warning(
                    emoji.emojize(custom_emoji, use_aliases=True) + ' Neutral')
            elif result == '[\'negative\']':
                st.info("Result")
                custom_emoji = ':disappointed:'
                st.error(
                    emoji.emojize(custom_emoji, use_aliases=True) +
                    ' Negative')

    elif input_choice == "Upload File":
        caching.clear_cache()
        if st.button('Download Sample Data'):
            df = pd.read_csv("test3.csv")
            csv = df.to_csv(index=False)
            b64 = base64.b64encode(csv.encode()).decode()
            href = f'<a href="data:file/csv;base64,{b64}" download="sample.csv">Download csv file</a>'
            st.markdown(href, unsafe_allow_html=True)

        data = st.file_uploader("Upload Dataset", type=["csv", "txt"])
        if data is not None:
            df = pd.read_csv(data, delimiter='\t')

            fig = go.Figure(data=[
                go.Table(header=dict(values=['Text']),
                         cells=dict(values=[df.Text]))
            ])
            st.plotly_chart(fig)

            st.info("Sentiment Result: ")

            all_sentences = df['Text'].to_list()
            all_sentiment = [model_predict(x) for x in all_sentences]
            new_df = pd.DataFrame(zip(all_sentences, all_sentiment),
                                  columns=["Text", "Sentiment"])

            a = len(df)
            a_pos = len(new_df[new_df['Sentiment'] == '[\'positive\']'])
            a_neu = len(new_df[new_df['Sentiment'] == '[\'neutral\']'])
            a_neg = len(new_df[new_df['Sentiment'] == '[\'negative\']'])

            fig = go.Figure(data=[
                go.Table(header=dict(values=['Text', 'Sentiment']),
                         cells=dict(values=[new_df.Text, new_df.Sentiment]))
            ])
            st.plotly_chart(fig)

            st.info("Download Result Here :")
            if st.button('Download Result as CSV'):
                tmp_download_link = download_link(
                    new_df, 'result.csv', 'Click here to download your data!')
                st.markdown(tmp_download_link, unsafe_allow_html=True)

            st.success('Positive Sentiment:')
            positive_df = new_df[new_df['Sentiment'] == "[\'positive\']"]

            if a_pos > 0:
                fig = go.Figure(data=[
                    go.Table(header=dict(values=['Text', 'Sentiment']),
                             cells=dict(values=[
                                 positive_df.Text, positive_df.Sentiment
                             ],
                                        fill_color="rgb(204,235,197)"))
                ])
                st.plotly_chart(fig)

            else:
                st.write('No Positive Sentiment')

            st.warning('Neutral Sentiment:')
            neutral_df = new_df[new_df['Sentiment'] == "[\'neutral\']"]
            if a_neu > 0:
                fig = go.Figure(data=[
                    go.Table(header=dict(values=['Text', 'Sentiment']),
                             cells=dict(values=[
                                 neutral_df.Text, neutral_df.Sentiment
                             ],
                                        fill_color="rgb(255,242,174)"))
                ])
                st.plotly_chart(fig)

            else:
                st.write('No Neutral Sentiment')

            st.error('Negative Sentiment:')
            negative_df = new_df[new_df['Sentiment'] == "[\'negative\']"]

            if a_neg > 0:
                fig = go.Figure(data=[
                    go.Table(header=dict(values=['Text', 'Sentiment']),
                             cells=dict(values=[
                                 negative_df.Text, negative_df.Sentiment
                             ],
                                        fill_color="rgb(249,123,114)"))
                ])
                st.plotly_chart(fig)

            else:
                st.write('No Negative Sentiment')

            st.info("Result Stats: ")
            st.write('Length of Data: {}'.format(a))

            pos, neu, neg = st.beta_columns(3)
            pos.success('\+ Positive Data : {}'.format(a_pos))
            neu.warning('= Neutral Data : {}'.format(a_neu))
            neg.error('\- Negative Data : {}'.format(a_neg))

            sentiment_count = [a_pos, a_neu, a_neg]
            sentiment = ['Positive', 'Neutral', 'Negative']

            large = (3.18, 2.625)
            # normal = (2.385, 1.9688)
            fig, ax = plt.subplots(figsize=large)

            width = 0.3
            ind = np.arange(len(sentiment_count))
            ax.barh(sentiment,
                    sentiment_count,
                    width,
                    color=my_cmap(my_norm(sentiment_count)))
            ax.set_yticklabels(sentiment, minor=False, fontsize=8)
            plt.title('Bar Chart', fontsize=8)
            for i, v in enumerate(sentiment_count):
                ax.text(v + .05,
                        i - .05,
                        str(v),
                        color='black',
                        fontweight='bold',
                        fontsize=8)
            st.pyplot()
예제 #14
0
def get_table_download_link(df):
    
    csv = df.to_csv(index=False)
    b64 = base64.b64encode(csv.encode()).decode() 
    href = f'<a href="data:file/csv;base64,{b64}" download="myfilename.csv">Download csv file</a>'
    return href