diff --git "a/app.py" "b/app.py" new file mode 100644--- /dev/null +++ "b/app.py" @@ -0,0 +1,3511 @@ +import streamlit as st +import pandas as pd +import pickle +import matplotlib.pyplot as plt +import numpy as np +import altair as alt +import plotly.graph_objects as go +import plotly.express as px +import statistics as stat +from streamlit_echarts import st_echarts +from streamlit_pandas_profiling import st_profile_report +from st_aggrid import AgGrid +# import pandas_profiling +from streamlit_vega_lite import vega_lite_component, altair_component +from statistics import mean +from datetime import datetime +import copy +st.set_page_config( + page_title="Real Time Social Medias Analysis", + page_icon="🧊", + layout="wide", + initial_sidebar_state="expanded", + menu_items={ + 'Get Help':None, + 'Report a bug': None, + 'About': "# This app gather social medias posts of 31 companies all around the world and then analysing it." + } + ) + + + +############ functions needed inside st +def make_clickable(link): + if link!="": + if "=" in link: + text = link.split('=')[0] + linki=link.split('=')[1] + return f'{text}' + else: + return link + else: + return "" + + + + +def check_password(): + """Returns `True` if the user had the correct password.""" + + def password_entered(): + + """Checks whether a password entered by the user is correct.""" + if st.session_state["password"] == "etka": + st.session_state["password_correct"] = True + del st.session_state["password"] # don't store password + else: + st.session_state["password_correct"] = False + + if "password_correct" not in st.session_state: + # First run, show input for password. + st.text_input( + "Password", type="password", on_change=password_entered, key="password" + ) + return False + elif not st.session_state["password_correct"]: + # Password not correct, show input + error. + st.text_input( + "Password", type="password", on_change=password_entered, key="password" + ) + st.error("😕 Password incorrect") + return False + else: + # Password correct. + return True +jkl=False +if check_password(): + jkl=True + +national_company_name_fa=['افق کوروش', 'جانبو', 'رفاه', 'فروشگاه هفت', 'هایپر استار', 'هایپر می', 'توی توی', 'شهروند', 'یاس', 'سورنا', 'وین مارکت', 'کیوان', 'فروشگاه سروش', 'سبوس', 'دیجی کالا', 'اکالا', 'ایمالز', 'اسنپ مارکت', 'فروشگاه کاله'] +international_company_name_fa=['والمارت', 'کروگر', 'کاستکو', 'بیم مارکت', 'میگروس', 'ساوکو', 'لولو هاپر مارکت', 'گروه یونیون', 'ادکا', 'آلدی', 'کارفور', 'بیلا راشا'] +company_name1_fa=national_company_name_fa+international_company_name_fa + +insta_accounts=['okcs.ir','canbo.ir','myrefah','haftstores','hyperstar_ir','hyperme.chainstores','toytoy.ir','shahrvand','yassgroup.official','surena.cs','winmarketco','k1megastore','soroush.chain.store','saboosgroup','digikalacom','okalaclub','emalls_site','snappmarket','kallehbrand','walmart','krogerco','costco','bimturkiye','migros_tr','saveco','luluhypermarkets','union.coop','edeka','aldiusa','carrefour_iraq','billarussia'] +company_name=['Ofogh Kouroush','Canbo','Refah','Haft Stores','Hyperstar','Hyper Me','Toy Toy','Shahrvand','Yaas','Surena','Win Market','K 1','Soroush Chain Store','Saboos Group','DigiKala','Okala','Emalls','Snapp Market','Kalleh Store','Walmart','Kroger','Costco','Bim','Migros','Save','LuLu Hypermarkets','Union','Edeka','Aldi','Carrefour','Billa Russia'] +company_name1=['Ofogh Kouroush','Canbo','Refah','Haft Stores','Hyperstar','Hyper Me','Toy Toy','Shahrvand','Yaas','Surena','Win Market','K 1','Soroush Chain Store','Saboos Group','DigiKala','Okala','Emalls','Snapp Market','Kalleh Store','Walmart','Kroger','Costco','Bim','Migros','Save','LuLu Hypermarkets','Union','Edeka','Aldi','Carrefour','Billa Russia'] +company_name2=['Ofogh_Kouroush','Canbo','Refah','Haft_Stores','Hyperstar','Hyper_Me','Toy_Toy','Shahrvand','Yaas','Surena','Win_Market','K_1','Soroush_Chain_Store','Saboos_Group','DigiKala','Okala','Emalls','Snapp_Market','Kalleh_Store','Walmart','Kroger','Costco','Bim','Migros','Save','LuLu_Hypermarkets','Union','Edeka','Aldi','Carrefour','Billa_Russia'] +national_insta_accounts = ['okcs.ir', 'canbo.ir', 'myrefah', 'haftstores', 'hyperstar_ir', 'hyperme.chainstores', 'toytoy.ir', 'shahrvand', 'yassgroup.official', 'surena.cs', 'winmarketco', 'k1megastore', 'soroush.chain.store', 'saboosgroup', 'digikalacom', 'okalaclub', 'emalls_site', 'snappmarket', 'kallehbrand'] +international_insta_accounts = ['walmart', 'krogerco', 'costco', 'bimturkiye', 'migros_tr', 'saveco', 'luluhypermarkets', 'union.coop', 'edeka', 'aldiusa', 'carrefour_iraq', 'billarussia'] +national_company_name = ['Ofogh Kouroush', 'Canbo', 'Refah', 'Haft Stores', 'Hyperstar', 'Hyper Me', 'Toy Toy', 'Shahrvand', 'Yaas', 'Surena', 'Win Market', 'K 1', 'Soroush Chain Store', 'Saboos Group', 'DigiKala', 'Okala', 'Emalls', 'Snapp Market', 'Kalleh Store'] +international_company_name = ['Walmart', 'Kroger', 'Costco', 'Bim', 'Migros', 'Save', 'LuLu Hypermarkets', 'Union', 'Edeka', 'Aldi', 'Carrefour', 'Billa Russia'] +national_company_name2 = ['Ofogh_Kouroush', 'Canbo', 'Refah', 'Haft_Stores', 'Hyperstar', 'Hyper_Me', 'Toy_Toy', 'Shahrvand', 'Yaas', 'Surena', 'Win_Market', 'K_1', 'Soroush_Chain_Store', 'Saboos_Group', 'DigiKala', 'Okala', 'Emalls', 'Snapp_Market', 'Kalleh_Store'] +international_company_name2 = ['Walmart', 'Kroger', 'Costco', 'Bim', 'Migros', 'Save', 'LuLu_Hypermarkets', 'Union', 'Edeka', 'Aldi', 'Carrefour', 'Billa_Russia'] +ide = [3145372723, 2965548667, 1988671655, 2197031285, 2233092127, 7485093484, 1181917352, 547966386, 2104826426, 7706142910, 7621001555, 4517720528, 1682386117, 1734407253, 1434739621, 6223711957, 1688949901, 7625600229, 536309671, 391362994, 1372092025, 1286044267, 6428046303, 324691922, 193450010, 1109269555, 1969219287, 1501689572, 525355730, 1494499024, 3646541728] +ide_national = [3145372723, 2965548667, 1988671655, 2197031285, 2233092127, 7485093484, 1181917352, 547966386, 2104826426, 7706142910, 7621001555, 4517720528, 1682386117, 1734407253, 1434739621, 6223711957, 1688949901, 7625600229, 536309671] +ide_international =[391362994, 1372092025, 1286044267, 6428046303, 324691922, 193450010, 1109269555, 1969219287, 1501689572, 525355730, 1494499024, 3646541728] +Website=['https://www.okcs.com','http://canbo.ir','http://refah.ir','http://www.7haftstores.com/Pages/index.aspx','https://www.hyperstariran.com','https://www.hyperme.ir','https://link.toytoy.ir/','https://www.shahrvand.ir','https://www.yassgroup.ir','https://surenacs.com','http://winmarketco.com','https://k1stores.com/?page_id=116','https://supersoroush.com','https://saboosgroup.ir','https://www.digikala.com','https://okala.com','https://emalls.ir','https://snapp.market','https://gilan.kalleh.com','https://www.walmart.com','https://www.kroger.com','https://www.costco.ca','https://www.bim.com.tr/Categories/104/magazalar.aspx','https://www.migros.com.tr','https://www.saveco.com','https://www.luluhypermarket.com/en-ae/','https://corporate.unioncoop.ae/en/online-shopping/','https://www.edeka.de','https://www.aldi.us','https://www.carrefouriraq.com','https://www.billa.ru'] +Instag=['https://www.instagram.com/okcs.ir/','https://www.instagram.com/canbo.ir/','https://www.instagram.com/myrefah/','https://www.instagram.com/haftstores/','https://www.instagram.com/hyperstar_ir/','https://www.instagram.com/hyperme.chainstores/','https://www.instagram.com/khaneh_kashaneh/','https://www.instagram.com/shahrvandeshop/','https://www.instagram.com/yassgroup.official/','https://www.instagram.com/surena.cs/','https://www.instagram.com/winmarketco/','https://www.instagram.com/k1megastore/','https://www.instagram.com/soroush.chain.store','https://www.instagram.com/saboosgroup/?hl=en','https://www.instagram.com/digikalacom/','https://www.instagram.com/okalaclub/','https://www.instagram.com/emalls_site/','https://www.instagram.com/snappmarket/','https://www.instagram.com/kallehbrand/','https://www.instagram.com/walmart/','https://www.instagram.com/krogerco/?hl=en','https://www.instagram.com/costco/?hl=en','https://www.instagram.com/bimturkiye/?hl=tr','https://www.instagram.com/migrossanalmarket/','https://www.instagram.com/saveco/','https://www.instagram.com/luluhypermarkets/','https://www.instagram.com/union.coop/','https://www.instagram.com/edeka/','https://www.instagram.com/aldiusa/','https://www.instagram.com/carrefour_iraq/','https://www.instagram.com/billarussia/'] +facebo=['https://www.facebook.com/ofoghkooroshstores','','','','','','','','','','https://www.facebook.com/winmarketco','https://www.facebook.com/profile.php?id=100030590948072','','','','','','','','https://www.facebook.com/walmart','https://www.facebook.com/Kroger/','https://www.facebook.com/CostcoCanada','https://www.facebook.com/bimturkiye','https://www.facebook.com/MSanalMarket','https://www.facebook.com/Savecoq8/','https://www.facebook.com/LuLuHypermarket/?brand_redir=1665762276970506','https://www.facebook.com/union.cooperative/','https://www.facebook.com/EDEKA','https://www.facebook.com/ALDI.USA','https://www.facebook.com/Carrefour.Iraq/','https://www.facebook.com/billa.ru'] +twitt=['https://twitter.com/ofoghkoorosh','','','','','','','','','','https://twitter.com/winmarketco1/','https://twitter.com/K1Megastore','','','https://twitter.com/digikalacom','','','','','https://twitter.com/Walmart','https://twitter.com/Kroger','','','https://twitter.com/MSanalMarket','https://twitter.com/savecoQ8','https://twitter.com/luluhypr','https://twitter.com/UnionCoop','https://twitter.com/AldiUSA','','',''] +youtu=['','','','','','','','','','','','','','','','','','','','https://www.youtube.com/user/Walmart','https://www.youtube.com/user/kroger','','https://www.youtube.com/channel/UClAHcndi08TXV0U3osnhQAQ/featured','https://www.youtube.com/user/migrossanalmarket/','https://www.youtube.com/channel/UCfEyO6rTOeca5SUeB3Wuw2Q','https://www.youtube.com/user/luluhypermarkets','https://www.youtube.com/user/unioncoop','https://www.youtube.com/user/aldiusa?feature=watch','https://www.youtube.com/user/aldiusa?feature=watch','https://www.youtube.com/user/CarrefourIraq/videos','https://www.youtube.com/channel/UCSx84zsrpnikJX2PDnOYbMA?sub_confirmation=1'] +pintres=['','','','','','','','','','','','','','','','','','','','https://www.pinterest.de/walmart/','https://www.pinterest.com/krogerco/','','','','','','https://www.pinterest.de/edeka/','https://www.pinterest.de/aldiusa/','','',''] +Linkdi=['https://www.linkedin.com/checkpoint/challengesV2/AQHGa5p3pWbEFgAAAXLmpWYtwLd1QPiyxE9LOCOU9YHEaZPoxyjNMuqSC2L4KiNIl-X079FNwycCwiZrh5wcGQYo-ansLaV8zg','https://www.linkedin.com/company/everest-modern-pars-chain-stores','','https://www.linkedin.com/company/oshanak-chain-stores-company-human-resources-department-','','','','','','','https://www.linkedin.com/company/winmarketco/','','','','https://www.linkedin.com/company/digikala/','','','','','','','','','','https://www.linkedin.com/authwall?trk=ripf&trkInfo=AQETU2kUtBRQNQAAAXLm9bl4bQDBlvDIfUZxUa_dLtjv3tqtxQfJEqEOxPkGITmOwZEh0VBky4JTEPPI2K-JLjqlevFNqsv1NweE9feyVANdc3JGzGQkZ2kSVeBnXF8wsBf4gFc=&originalReferer=&sessionRedirect=https%3A%2F%2Fwww.linkedin.com%2Fcompany%2Fsaveco','','https://www.linkedin.com/authwall?trk=ripf&trkInfo=AQHx-TF6N6AmVQAAAXLm-34II5OTK0P5oy4dX42TB2T2yQSTNcgCIa4u3B00JR2NJtdKGbQq4MTAX6o-vlhxIN8kUcHA8ICQPIA2g5qGTmqNTwypN3CIhy6Gm-XG5xi-1HkJQVU=&originalReferer=&sessionRedirect=https%3A%2F%2Fae.linkedin.com%2Fin%2Funioncoop','','','',''] +Telegra=['https://t.me/okclub','https://telegram.me/canbo','http://telegram.me/myrefah','https://telegram.me/HAFTSTORESS','','https://telegram.me/hyperme_ir','https://t.me/hyperfamili','','','','http://telegram.me/winmarketco','https://t.me/k1megastore','','https://t.me/saboosgroup','','https://t.me/okala_club1/','','','','','','','','','','','','','','',''] +Whatsap=['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''] +Soru=['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''] +Bale=['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''] +igap=['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''] +aparat=['https://www.aparat.com/okclub','','','','https://www.aparat.com/Hyperstariran','','','https://www.aparat.com/shahrvand.ir','','https://www.aparat.com/surenacs','https://www.aparat.com/winmarketco','https://www.aparat.com/k1megastore','','','https://www.aparat.com/digikala/دیجی_کالا','https://www.aparat.com/okala/','','','','','','','','','','','','','','',''] +robica=['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''] + + + + +kindii=["Takhfif","Jashn","Mosabeghe","Mahsol"] +kindii_fa=["تخفیف","جشنواره","مسابقه","ارتقای محصول"] + + + + + +########## load the dataset +data=pickle.load(open("data/data.pkl","rb")) + + +######## make sheet 1 + + + + +company=national_company_name_fa+["کل","٪ شرکت ها","میانگین حساب کاربری هر شرکت"] +instagram=["*" for i in range(19)]+["19","100",""] +facebook=["*" if i==0 or i==10 or i==11 else "" for i in range(19)]+["3","15.79",""] +twitter=["*" if i==0 or i==10 or i==11 or i==14 else "" for i in range(19)]+["4","21.05",""] +linkedin=["*" if i==0 or i==10 or i==1 or i==14 or i==3 else "" for i in range(19)]+["5","26.32",""] +telegram=["*" if i<=3 or i==5 or i==6 or i==10 or i==11 or i==13 or i==15 else "" for i in range(19)]+["10","52.63",""] +Aparat=["*" if i==0 or i==4 or i==7 or i==10 or i==9 or i==10 or i==15 or i==14 else "" for i in range(19)]+["8","42.11",""] +sorosh=["" for i in range(19)]+["0","0",""] +bale=["" for i in range(19)]+["0","0",""] +igap=["" for i in range(19)]+["0","0",""] +robica=["" for i in range(19)]+["0","0",""] +total=['6', '3', '2', '3', '2', '2', '2', '2', '1', '2', '6', '5', '1', '2', '4', '3', '1', '1', '1', '49', '', ''] + +website_national=[f"*={Website[i]}" if Website[i]!="" else "" for i in range(19)]+["19","100","2.58"] +insta_national=[f"*={Instag[i]}" if Instag[i]!="" else "" for i in range(19)]+["19","100",""] +facebook_national=[f"*={facebo[i]}" if facebo[i]!="" else "" for i in range(19)]+["3","15.79",""] + +twitter_national=[f"*={twitt[i]}" if twitt[i]!="" else "" for i in range(19)]+["4","21.05",""] + +linkedin_natioanl=[f"*={Linkdi[i]}" if Linkdi[i]!="" else "" for i in range(19)]+["5","26.32",""] + +aparat_national=[f"*={aparat[i]}" if aparat[i]!="" else "" for i in range(19)]+["8","42.11",""] + +telegram_national=[f"*={Telegra[i]}" if Telegra[i]!="" else "" for i in range(19)]+["10","52.63",""] + + + +sheet1=pd.DataFrame(data={"شرکت ها":company ,"وب سایت":website_national,"اینستاگرام":insta_national,"فیسبوک":facebook_national, +"توییتر":twitter_national,"لینکدین":linkedin_natioanl,"تلگرام":telegram_national, +"آپارات":aparat_national,"کل":total +}) +for j in ["وب سایت","اینستاگرام","فیسبوک","توییتر","لینکدین","تلگرام","آپارات"]: + sheet1[j]=sheet1[j].apply(make_clickable) + +sheet1=sheet1.to_html(escape=False) + + +del company,instagram,facebook,twitter,linkedin,telegram,Aparat,sorosh,bale,igap,robica,total,website_national,insta_national,facebook_national,twitter_national,linkedin_natioanl,aparat_national,telegram_national + + + + + + + +sheet7_0data=[6,3,2,3,2,2,2,2,1,2,6,5,1,2,4,3,1,1,1] +dfsheet0= pd.DataFrame(data={"Companies":national_company_name_fa,"The Number of Accounts":sheet7_0data}) + + + + + +company=international_company_name_fa+["کل","٪ شرکت‌ها","میانگین حساب کاربری هر شرکت"] +instagram=["*" for i in range(12)]+["12","100","2.53"] +facebook=["*" for i in range(12)]+["12","100",""] +pintrest=["*" if i<=1 or i==7 or i==8 else "" for i in range(12)]+["4","33.33",""] +twitter=["*" if i<=1 or (i>=4 and i<=8) else "" for i in range(12)]+["7","58.33",""] +youtube=["*" if i<=1 or (i>=3 and i<=11) else "" for i in range(12)]+["11","91.67",""] +linkedin=["*" if i==5 or i==7 else "" for i in range(12)]+["2","16.67",""] +whatsapp=["" for i in range(12)]+["0","0",""] +total=['5', '5', '2', '3', '4', '5', '4', '6', '5', '3', '3', '3', '48',"",""] + + + +insta_international=[f"*={Instag[i+19]}" if Instag[i+19]!="" else "" for i in range(12)]+["12","100",""] +website_international=[f"*={Website[i+19]}" if Website[i+19]!="" else "" for i in range(12)]+["12","100","2.53"] +facebook_international=[f"*={facebo[i+19]}" if facebo[i+19]!="" else "" for i in range(12)]+["12","100",""] +twitter_international=[f"*={twitt[i+19]}" if twitt[i+19]!="" else "" for i in range(12)]+["7","58.33",""] +linkedin_internatioanl=[f"*={Linkdi[i+19]}" if Linkdi[i+19]!="" else "" for i in range(12)]+["2","16.67",""] +youtube_international=[f"*={youtu[i+19]}" if youtu[i+19]!="" else "" for i in range(12)]+["11","91.67",""] +pintrest_international=[f"*={pintres[i+19]}" if pintres[i+19]!="" else "" for i in range(12)]+["4","33.33",""] + + +sheet1_1=pd.DataFrame(data={"شرکت ها":company,"وب سایت":website_international,"اینستاگرام":insta_international,"فیسبوک":facebook_international,"پینترست":pintrest_international, + + "توییتر":twitter_international,"یوتیوب":youtube_international,"لینکدین":linkedin_internatioanl,"کل":total + }) + +for j in ["وب سایت","اینستاگرام","فیسبوک","توییتر","لینکدین","یوتیوب","پینترست"]: + sheet1_1[j]=sheet1_1[j].apply(make_clickable) +sheet1_1=sheet1_1.to_html(escape=False) + +del company,instagram,facebook,pintres,twitter,youtube,linkedin,whatsapp,total,insta_international,website_international,facebook_international,twitter_international,linkedin_internatioanl,youtube_international,pintrest_international + + + +sheet7_0data=[5,5,2,3,4,5,4,6,5,3,3,3] +dfsheet0_1 = pd.DataFrame(data={"Companies":international_company_name_fa,"The Number of Accounts":sheet7_0data}) + + + +source0_1 = pd.DataFrame({"Popularities": [12,12,4,7,11,2,0],"Social Medias":['Instagram','FaceBook','Pintrest','Twitter','Youtube','LinkedIn','WhatsApp']}) + + + + + + + + + + +###### make sheet2 dataframe + +followers=[] +following=[] +posts=[] + +for i in national_company_name2: + followers.append(data["information"][i]["bio"]["followers"]) + following.append(data["information"][i]["bio"]["following"]) + posts.append(data["information"][i]["bio"]["posts_count"]) +sheet2=pd.DataFrame(data={"شرکت ها":national_company_name_fa,"تعداد دنبال کنندگان":followers,"تعداد دنبال کرده ها":following,"تعداد پست ها":posts}) +sheet2bar=pd.DataFrame(data={"Companies":national_company_name_fa,"Followers":followers}) +sheet2barpost=pd.DataFrame(data={"Companies":national_company_name_fa,"Number of posts":posts}) +sheet3followers=followers + + + + +followers=[] +following=[] +posts=[] +for i in international_company_name2: + followers.append(data["information"][i]["bio"]["followers"]) + following.append(data["information"][i]["bio"]["following"]) + posts.append(data["information"][i]["bio"]["posts_count"]) +sheet2_1=pd.DataFrame(data={"شرکت ها":international_company_name_fa,"تعداد دنبال کنندگان":followers,"تعداد دنبال کرده ها":following,"تعداد پست ها":posts}) +sheet2bar_1=pd.DataFrame(data={"Companies":international_company_name_fa,"Followers":followers}) +sheet2barpost_1=pd.DataFrame(data={"Companies":international_company_name_fa,"Number of posts":posts}) +sheet3_1followers=followers + + +del followers,following,posts + + + + +######### make sheet 3 for national and international companies post analysis + +temp=["بیشترین تعداد پسندیده شدن" ,"بیشترین تعداد نظرات","بیشترین تعداد بازدی","میانگین تعداد پسندیده شدن","میانگین تعداد نظرات","میانگین تعداد بازدید","میانگین مشارکت","٪ تصاویر","٪ ویدیو ها","میانگین روزانه تعداد پست","میانگین ساعتی تعداد پست ها"] +temp2=["max_like","max_comment","max_view","ave_like","ave_comment","ave_view","ave_participation","percent_image","percent_video","ave_post_per_day","ave_post_per_hour"] +company=[] +time_horizon=[] +last_month=[] +last_three_months=[] +overal=[] +tir2=[last_month,last_three_months,overal] +sheet3like=[[] for i in range(3)] +sheet3comment=[[] for i in range(3)] +sheet3view=[[] for i in range(3)] +sheet3participation=[[] for i in range(3)] +sheet3image=[[] for i in range(3)] +sheet3postperday=[[] for i in range(3)] +tir=["last_month","last_three_months","overal"] +for i in national_company_name2: + index=national_company_name2.index(i) + for j in temp: + if temp.index(j)==0: + company.append(national_company_name_fa[index]) + else : + company.append("") + time_horizon.append(j) + for j in tir: + index=tir.index(j) + for t in temp2: + if temp2.index(t)==7 or temp2.index(t)==8: + tir2[index].append("{:.0f}".format(data["information"][i]["analysis"]["participation"][j][t]*100)+" %") + if temp2.index(t)==7 : + sheet3image[index].append(data["information"][i]["analysis"]["participation"][j][t]) + elif temp2.index(t)==9 or temp2.index(t)==10: + tir2[index].append("{:.2f}".format(data["information"][i]["analysis"]["participation"][j][t])) + if temp2.index(t)==9 : + sheet3postperday[index].append(data["information"][i]["analysis"]["participation"][j][t]) + else: + tir2[index].append("{:.0f}".format(data["information"][i]["analysis"]["participation"][j][t])) + if t=="ave_like": + sheet3like[index].append(data["information"][i]["analysis"]["participation"][j][t]) + elif t=="ave_comment": + sheet3comment[index].append(data["information"][i]["analysis"]["participation"][j][t]) + elif t=="ave_view": + sheet3view[index].append(data["information"][i]["analysis"]["participation"][j][t]) + elif t=="ave_participation": + sheet3participation[index].append(data["information"][i]["analysis"]["participation"][j][t]) +sheet3=pd.DataFrame(data={"شرکت ها":company,"افق زمانی":time_horizon,"یک ماه اخیر":tir2[0],"سه ماه اخیر":tir2[1],"کل":tir2[2]}) + + +del company,time_horizon,tir2,last_month,last_three_months,overal + + + +temp=["بیشترین تعداد پسندیده شدن" ,"بیشترین تعداد نظرات","بیشترین تعداد بازدی","میانگین تعداد پسندیده شدن","میانگین تعداد نظرات","میانگین تعداد بازدید","میانگین مشارکت","٪ تصاویر","٪ ویدیو ها","میانگین روزانه تعداد پست","میانگین ساعتی تعداد پست ها"] +temp2=["max_like","max_comment","max_view","ave_like","ave_comment","ave_view","ave_participation","percent_image","percent_video","ave_post_per_day","ave_post_per_hour"] +company=[] +time_horizon=[] +last_month=[] +last_three_months=[] +overal=[] +tir2=[last_month,last_three_months,overal] +sheet3like_1=[[] for i in range(3)] +sheet3comment_1=[[] for i in range(3)] +sheet3view_1=[[] for i in range(3)] +sheet3participation_1=[[] for i in range(3)] +sheet3image_1=[[] for i in range(3)] +sheet3postperday_1=[[] for i in range(3)] +tir=["last_month","last_three_months","overal"] +for i in international_company_name2: + index=international_company_name2.index(i) + for j in temp: + if temp.index(j)==0: + company.append(international_company_name_fa[index]) + else : + company.append("") + time_horizon.append(j) + for j in tir: + index=tir.index(j) + for t in temp2: + if temp2.index(t)==7 or temp2.index(t)==8: + tir2[index].append("{:.0f}".format(data["information"][i]["analysis"]["participation"][j][t]*100)+" %") + if temp2.index(t)==7 : + sheet3image_1[index].append(data["information"][i]["analysis"]["participation"][j][t]) + elif temp2.index(t)==9 or temp2.index(t)==10: + tir2[index].append("{:.2f}".format(data["information"][i]["analysis"]["participation"][j][t])) + if temp2.index(t)==9 : + sheet3postperday_1[index].append(data["information"][i]["analysis"]["participation"][j][t]) + else: + tir2[index].append("{:.0f}".format(data["information"][i]["analysis"]["participation"][j][t])) + if t=="ave_like": + sheet3like_1[index].append(data["information"][i]["analysis"]["participation"][j][t]) + elif t=="ave_comment": + sheet3comment_1[index].append(data["information"][i]["analysis"]["participation"][j][t]) + elif t=="ave_view": + sheet3view_1[index].append(data["information"][i]["analysis"]["participation"][j][t]) + elif t=="ave_participation": + sheet3participation_1[index].append(data["information"][i]["analysis"]["participation"][j][t]) + + +sheet3_1=pd.DataFrame(data={"شرکت ها":company,"افق زمانی":time_horizon,"یک ماه اخیر":tir2[0],"سه ماه اخیر":tir2[1],"کل":tir2[2]}) + +del tir2,company + + + + + + + + + +#################### sheet 4 hashtag + + +company=[] +temp=["��یانگین تعداد # ها در هر پست","بیشترین تعداد # در یک پست","کم ترین تعداد # در یک پست","محبوب ترین # های استفاده شده"] +time_horizon=[] +tom=[[],[],[]] +hori=["last_month","last_three_months","overal"] +avermax=[[[],[],[]],[[],[],[]]] +kori=["averge_per_post","max_number","min_number","most_common"] +for i in national_company_name2: + for t in temp: + if temp.index(t)==0: + company.append(national_company_name_fa[national_company_name2.index(i)]) + else: + company.append("") + + time_horizon.append(t) + for j in range(3): + for c in kori: + if c=="most_common": + + if len(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c]) !=0 : + h="" + for g in range(len(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c])): + if g!=len(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c])-1: + h+=data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c][g][0]+" - " + else: + h+=data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c][g][0] + tom[j].append(h) + else: + tom[j].append("") + else: + tom[j].append("{:.2f}".format(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c])) + if c=="averge_per_post": + avermax[0][j].append(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c]) + elif c=="max_number": + avermax[1][j].append(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c]) + + + + +sheet4=pd.DataFrame(data={"شرکت‌ها":company,"افق زمانی":time_horizon,"یک ماه اخیر":tom[0],"سه ماه اخیر":tom[1],"کل":tom[2]}) +capdia40=[] +for i in range(2): + capdia40.append(pd.DataFrame( + { + "Company":national_company_name_fa, + "Last Month":avermax[i][0], + "Last Three Months":avermax[i][1], + "Overal":avermax[i][2]}, + columns=['Company', 'Last Month', 'Last Three Months','Overal'] + )) + + +del h,j,c,t,i,kori,tom,time_horizon,temp,company,avermax + + + +company=[] +temp=["میانگین تعداد # ها در هر پست","بیشترین تعداد # در یک پست","کم ترین تعداد # در یک پست","محبوب ترین # های استفاده شده"] +time_horizon=[] +tom=[[],[],[]] +hori=["last_month","last_three_months","overal"] +avermax=[[[],[],[]],[[],[],[]]] +kori=["averge_per_post","max_number","min_number","most_common"] +for i in international_company_name2: + for t in temp: + if temp.index(t)==0: + company.append(international_company_name_fa[international_company_name2.index(i)]) + else: + company.append("") + + time_horizon.append(t) + for j in range(3): + for c in kori: + if c=="most_common": + + if len(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c]) !=0 : + h="" + for g in range(len(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c])): + if g!= len(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c])-1: + + h+=data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c][g][0]+" - " + else: + h+=data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c][g][0] + tom[j].append(h) + else: + tom[j].append("") + else: + tom[j].append("{:.2f}".format(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c])) + if c=="averge_per_post": + avermax[0][j].append(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c]) + elif c=="max_number": + avermax[1][j].append(data["information"][i]["analysis"]["hashtag"][hori[j]]["all_posts_type"][c]) + + +sheet4_1=pd.DataFrame(data={"شرکت‌ها":company,"افق زمانی":time_horizon,"یک ماه اخیر":tom[0],"سه ماه اخیر":tom[1],"کل":tom[2]}) +capdia4=[] +for i in range(2): + capdia4.append(pd.DataFrame( + { + "Company":international_company_name_fa, + "Last Month":avermax[i][0], + "Last Three Months":avermax[i][1], + "Overal":avermax[i][2]}, + columns=['Company', 'Last Month', 'Last Three Months','Overal'] + )) + + + + +del h,j,c,t,i,kori,tom,time_horizon,temp,company,avermax + + + + + + +############ sheet5 emoji + +company=[] +temp=["میانگین تعداد اموجی‌ها در هر پست","بیشترین تعداد اموجی‌‌ها در یک پست","کم ترین تعداد اموجی‌‌ها در یک پست","محبوب ترین اموجی‌های استفاده شده"] +time_horizon=[] +tom=[[],[],[]] +hori=["last_month","last_three_months","overal"] +avermax=[[[],[],[]],[[],[],[]]] +kori=["averge_per_post","max_number","min_number","most_common"] +for i in national_company_name2: + for t in temp: + if temp.index(t)==0: + company.append(national_company_name_fa[national_company_name2.index(i)]) + else: + company.append("") + + time_horizon.append(t) + for j in range(3): + for c in kori: + if c=="most_common": + + if len(data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c]) !=0 : + h="" + for g in range(len(data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c])): + h+=data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c][g][0] + tom[j].append(h) + else: + tom[j].append("") + else: + tom[j].append("{:.2f}".format(data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c])) + if c=="averge_per_post": + avermax[0][j].append(data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c]) + elif c=="max_number": + avermax[1][j].append(data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c]) + +sheet5=pd.DataFrame(data={"شرکت‌ها":company,"افق زمانی":time_horizon,"یک ماه اخیر":tom[0],"سه ماه اخیر":tom[1],"کل":tom[2]}) + +capdia50=[] +for i in range(2): + capdia50.append(pd.DataFrame( + { + "Company":national_company_name_fa, + "Last Month":avermax[i][0], + "Last Three Months":avermax[i][1], + "Overal":avermax[i][2]}, + columns=['Company', 'Last Month', 'Last Three Months','Overal'] + )) + + + +del h,j,c,t,i,kori,tom,time_horizon,temp,company,avermax + +company=[] +temp=["میانگین تعداد اموجی‌ها در هر پست","بیشترین تعداد اموجی‌‌ها در یک پست","کم ترین تعداد اموجی‌‌ها در یک پست","محبوب ترین اموجی‌های استفاده شده"] +time_horizon=[] +tom=[[],[],[]] +hori=["last_month","last_three_months","overal"] +avermax=[[[],[],[]],[[],[],[]]] +kori=["averge_per_post","max_number","min_number","most_common"] +for i in international_company_name2: + for t in temp: + if temp.index(t)==0: + company.append(international_company_name_fa[international_company_name2.index(i)]) + else: + company.append("") + + time_horizon.append(t) + for j in range(3): + for c in kori: + if c=="most_common": + + if len(data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c]) !=0 : + h="" + for g in range(len(data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c])): + h+=data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c][g][0] + tom[j].append(h) + else: + tom[j].append("") + else: + tom[j].append("{:.2f}".format(data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c])) + if c=="averge_per_post": + avermax[0][j].append(data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c]) + elif c=="max_number": + avermax[1][j].append(data["information"][i]["analysis"]["emoji"][hori[j]]["all_posts_type"][c]) + +sheet5_1=pd.DataFrame(data={"شرکت‌ها":company,"افق زمانی":time_horizon,"یک ماه اخیر":tom[0],"سه ماه اخیر":tom[1],"کل":tom[2]}) + +capdia5=[] +for i in range(2): + capdia5.append(pd.DataFrame( + { + "Company":international_company_name_fa, + "Last Month":avermax[i][0], + "Last Three Months":avermax[i][1], + "Overal":avermax[i][2]}, + columns=['Company', 'Last Month', 'Last Three Months','Overal'] + )) + + +del h,j,c,t,i,kori,tom,time_horizon,temp,company,avermax + + + + + + + +######### sheet 6 common words + +company=[] +temp=["میانگین تعداد لغات در هر پست","بیشترین تعداد لغات در یک پست","کم ترین تعداد لغات در یک پست","محبوب ترین لغات استفاده شده"] +time_horizon=[] +tom=[[],[],[]] +hori=["last_month","last_three_months","overal"] +avermax=[[[],[],[]],[[],[],[]]] +kori=["averge_per_post","max_number","min_number","most_common"] +for i in national_company_name2: + for t in temp: + if temp.index(t)==0: + company.append(national_company_name_fa[national_company_name2.index(i)]) + else: + company.append("") + + time_horizon.append(t) + for j in range(3): + for c in kori: + if c=="most_common": + + if len(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c]) !=0 : + h="" + for g in range(len(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c])): + if g!=len(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c])-1: + h=h+data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c][g][0]+"، " + else: + h+=data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c][g][0] + + tom[j].append(h) + else: + tom[j].append("") + else: + tom[j].append("{:.2f}".format(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c])) + if c=="averge_per_post": + avermax[0][j].append(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c]) + elif c=="max_number": + avermax[1][j].append(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c]) + +sheet6=pd.DataFrame(data={"شرکت‌ها":company,"افق زمانی":time_horizon,"یک ماه اخیر":tom[0],"سه ماه اخیر":tom[1],"کل":tom[2]}) + + + +capdia0=[] +for i in range(2): + capdia0.append(pd.DataFrame( + { + "Company":national_company_name_fa, + "Last Month":avermax[i][0], + "Last Three Months":avermax[i][1], + "Overal":avermax[i][2]}, + columns=['Company', 'Last Month', 'Last Three Months','Overal'] + )) + + + +del h,j,c,t,i,kori,tom,time_horizon,temp,company,avermax + +company=[] +temp=["میانگین تعداد لغات در هر پست","بیشترین تعداد لغات در یک پست","کم ترین تعداد لغات در یک پست","محبوب ترین لغات استفاده شده"] +time_horizon=[] +tom=[[],[],[]] +hori=["last_month","last_three_months","overal"] +avermax=[[[],[],[]],[[],[],[]]] +kori=["averge_per_post","max_number","min_number","most_common"] +for i in international_company_name2: + for t in temp: + if temp.index(t)==0: + company.append(international_company_name_fa[international_company_name2.index(i)]) + else: + company.append("") + + time_horizon.append(t) + for j in range(3): + for c in kori: + if c=="most_common": + + if len(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c]) !=0 : + h="" + for g in range(len(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c])): + if g!=len(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c])-1: + h=h+data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c][g][0]+"، " + else: + h+=data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c][g][0] + tom[j].append(h) + else: + tom[j].append("") + else: + tom[j].append("{:.2f}".format(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c])) + if c=="averge_per_post": + avermax[0][j].append(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c]) + elif c=="max_number": + avermax[1][j].append(data["information"][i]["analysis"]["caption"][hori[j]]["all_posts_type"][c]) + +sheet6_1=pd.DataFrame(data={"شرکت‌ها":company,"افق زمانی":time_horizon,"یک ماه اخیر":tom[0],"سه ماه اخیر":tom[1],"کل":tom[2]}) + + + + +capdia=[] +for i in range(2): + capdia.append(pd.DataFrame( + { + "Company":international_company_name_fa, + "Last Month":avermax[i][0], + "Last Three Months":avermax[i][1], + "Overal":avermax[i][2]}, + columns=['Company', 'Last Month', 'Last Three Months','Overal'] + )) + + +del h,j,c,t,i,kori,tom,time_horizon,temp,company,avermax + + + + + + + + + + + + + + + +########## sheet7 populars + + + + + + + + +company1=data["pop"]["companies"]["national"]["list"] +follo=[sheet3followers[national_company_name.index(i)] for i in company1] +company1_fa=[national_company_name_fa[national_company_name.index(i)] for i in company1] +sheet7a=pd.DataFrame(data={"Companies Popularitites Based on Followers (sorted in decending order)":company1_fa,"Followers":follo}) + +company1=data["pop"]["companies"]["international"]["list"] +follo=[sheet3_1followers[international_company_name.index(i)] for i in company1] +company1_fa=[international_company_name_fa[international_company_name.index(i)] for i in company1] +sheet7a_1=pd.DataFrame(data={"Companies Popularitites Based on Followers (sorted in decending order)":company1_fa,"Followers":follo}) +del company1,follo + + + +time_horizon=["last_month","last_three_months","overal"] + +kind=["like","comment","view","engagement"] +sheeta=[] + +sheeta_diagram=[] +kinda12=["Like","Comment","View","Engagement"] +for i in kind : + ranka=[[] for i in range(3)] + timie=[] + timie_fa=[] + for j in time_horizon: + + timie_fa.append([national_company_name_fa[national_company_name.index(l)] for l in data["pop"]["national"][j][i]["list"]]) + timie.append(data["pop"]["national"][j][i]["list"]) + ranka[time_horizon.index(j)]=[(timie[time_horizon.index(j)].index(k))+1 for k in national_company_name ] + + sheeta.append(pd.DataFrame(data={"یک ماه اخیر":timie_fa[0],"سه ماه اخیر":timie_fa[1],"کل":timie_fa[2]})) + sheeta_diagram.append(pd.DataFrame( + { + "Company":national_company_name_fa, + "Last Month":ranka[0], + "Last Three Months":ranka[1], + "Overal":ranka[2] + }, + columns=["Company","Last Month","Last Three Months","Overal"] + )) + + + +sheeta_1=[] +timie=[] +sheeta_1diagram=[] + +for i in kind : + timie=[] + timie_fa=[] + ranka=[[] for i in range(3)] + for j in time_horizon: + timie.append(data["pop"]["international"][j][i]["list"]) + timie_fa.append([international_company_name_fa[international_company_name.index(l)] for l in data["pop"]["international"][j][i]["list"]]) + ranka[time_horizon.index(j)]=[(timie[time_horizon.index(j)].index(k))+1 for k in international_company_name ] + sheeta_1.append(pd.DataFrame(data={"یک ماه اخیر":timie_fa[0],"سه ماه اخیر":timie_fa[1],"کل":timie_fa[2]})) + sheeta_1diagram.append(pd.DataFrame( + { + "Company":international_company_name_fa, + "Last Month":ranka[0], + "Last Three Months":ranka[1], + "Overal":ranka[2] + }, + columns=["Company","Last Month","Last Three Months","Overal"] + )) + sheeta_1diagram[kind.index(i)]= sheeta_1diagram[kind.index(i)].melt("Company",var_name="Time Horizon",value_name=kinda12[kind.index(i)]) + + +del time_horizon,i,j,timie ,timie_fa + + +sheet7_0=pd.DataFrame(data={"Populars Social Medias":["Instagram","Telegram","Aparat","LinkdIn","Twitter","Facebook","Robica","iGap","Bale","Soroush","Whatsapp","Youtube","Pintrest"]}) +sheet7_0_1=pd.DataFrame(data={"Populars Social Medias":["Facebook","Instagram","Youtube","Twitter","Pintrest","LinkdIn","Whatsapp"]}) + + +#st.dataframe(sheet7_0) +sheet7_0data=[19,10,8,5,4,3,0,0,0,0,0,0,0] +she3=['19','10','8','5','4','3','0','0','0','0','0','0','0'] +num=["Instagram","Telegram","Aparat","LinkdIn","Twitter","Facebook","Robica","iGap","Bale","Soroush","Whatsapp","Youtube","Pintrest"] +num_fa=["اینستاگرام","تلگرام","آپارات","لینکدین","توییتر","فیسبوک","روبیکا","آی گپ","بله","سروش","واتس اپ","یوتیوب","پینترست"] +df23 = pd.DataFrame(data={"Social Medias":num,"The Number of Companies That Are Active In It":sheet7_0data}) +def left_align(s, props='text-align: left;'): + return props +df12 = pd.DataFrame(data={"شبکه‌های اجتماعی":num_fa,"تعداد شرکت‌ها در هر شبکه‌ی اجتماعی":she3}) + + +#df12=df12.style.applymap(left_align) + +sheet7_0data=[12,12,11,7,4,2,0] +she3=['12','12','11','7','4','2','0'] +num=["Facebook","Instagram","Youtube","Twitter","Pintrest","LinkdIn","Whatsapp"] +num_fa=["فیسبوک","اینستاگرام","یوتیوب","توییتر","پینترست","لینکدین","واتس اپ"] + +df23_1 = pd.DataFrame(data={"Social Medias":num,"The Number of Companies That Are Active In It":sheet7_0data}) +def left_align(s, props='text-align: left;'): + return props +df12_1 = pd.DataFrame(data={"Social Medias":num_fa,"The Number of Companies":she3}) + + + +del num,she3,sheet7_0data + + + +############# sheet8 content Anlaysis + + +maxi_national=[[0 for i in national_company_name2] for c in range(3)] +content_national=[["Other" for i in national_company_name2] for c in range(3)] +for i in national_company_name2: + ind=national_company_name2.index(i) + for f in ["last_month","last_three_months","overal"]: + inf=["last_month","last_three_months","overal"].index(f) + for j in data["information"][i]["analysis"]["caption"][f]["all_posts_type"]["anal"]: + if data["information"][i]["analysis"]["caption"][f]["all_posts_type"]["anal"][j]>maxi_national[inf][ind]: + maxi_national[inf][ind]= data["information"][i]["analysis"]["caption"][f]["all_posts_type"]["anal"][j] + content_national[inf][ind]=j.capitalize() + + + +maxi_international=[[0 for i in international_company_name2] for c in range(3)] +content_international=[["Other" for i in international_company_name2] for c in range(3)] +for i in international_company_name2: + ind=international_company_name2.index(i) + for f in ["last_month","last_three_months","overal"]: + inf=["last_month","last_three_months","overal"].index(f) + for j in data["information"][i]["analysis"]["caption"][f]["all_posts_type"]["anal"]: + if data["information"][i]["analysis"]["caption"][f]["all_posts_type"]["anal"][j]>maxi_international[inf][ind]: + maxi_international[inf][ind]= data["information"][i]["analysis"]["caption"][f]["all_posts_type"]["anal"][j] + content_international[inf][ind]=j.capitalize() + +def asem(a): + if isinstance(a,str): + if a=="Mahsol": + return "معرفی محصولات" + elif a=="Takhfif": + return "معرفی کالاهای تخفیف خورده" + elif a=="Jashn": + return "جشنوارهای فروش" + elif a=="Mosabeghe": + return "مسابقه" + elif a=="Other": + return "سایر محتواها" + else: + return a + else: + return a + +national_pop_content=stat.mode([i for i in content_national[0] if i!="Other"]) +international_pop_content=stat.mode([i for i in content_international[0] if i!="Other"]) +sheet8=pd.DataFrame(data={ + "شرکت":national_company_name_fa, + "یک ماه اخیر": [asem(i) for i in content_national[0]], + "سه ماه اخیر":[asem(i) for i in content_national[1]], + "کل":[asem(i) for i in content_national[2]], + "ind":[i+1 for i in range(19)] + }) + +sheet8diagram=pd.DataFrame(data={ + "Content":[asem("Mosabeghe"),asem("Jashn"),asem("Takhfif"),asem("Mahsol")], + "Last Month":[content_national[0].count("Mosabeghe"),content_national[0].count("Jashn"),content_national[0].count("Takhfif"),content_national[0].count("Mahsol")], + "Last Three Months":[content_national[1].count("Mosabeghe"),content_national[1].count("Jashn"),content_national[1].count("Takhfif"),content_national[1].count("Mahsol")], + "Overal":[content_national[2].count("Mosabeghe"),content_national[2].count("Jashn"),content_national[2].count("Takhfif"),content_national[2].count("Mahsol")] + }) + +sheet8_1diagram=pd.DataFrame(data={ + "Content":[asem("Mosabeghe"),asem("Jashn"),asem("Takhfif"),asem("Mahsol")], + "Last Month":[content_international[0].count("Mosabeghe"),content_international[0].count("Jashn"),content_international[0].count("Takhfif"),content_international[0].count("Mahsol")], + "Last Three Months":[content_international[1].count("Mosabeghe"),content_international[1].count("Jashn"),content_international[1].count("Takhfif"),content_international[1].count("Mahsol")], + "Overal":[content_international[2].count("Mosabeghe"),content_international[2].count("Jashn"),content_international[2].count("Takhfif"),content_international[2].count("Mahsol")] + }) + +sheet8_1=pd.DataFrame(data={ + "شرکت":international_company_name_fa, + "یک ماه اخیر": [asem(i) for i in content_international[0]], + "سه ماه اخیر":[asem(i) for i in content_international[1]], + "کل":[asem(i) for i in content_international[2]], + "ind":[i+1 for i in range(12)] + }) +del maxi_national,maxi_international,content_international,content_national + + + +################ sheet 9 popular posts + + + + +############### ave posting per day +ave_post_perday_national_last_month=0 +for i in data["pop"]["time"]["national"]["day"]["last_month"]: + ave_post_perday_national_last_month+=i +ave_post_perday_national_last_month=ave_post_perday_national_last_month/(33*7*19) + + +ave_post_perday_national_last_three_month=0 +for i in data["pop"]["time"]["national"]["day"]["last_three_months"]: + ave_post_perday_national_last_three_month+=i +ave_post_perday_national_last_three_month=ave_post_perday_national_last_three_month/(99*7*19) + + +ave_post_perday_international_last_month=0 +for i in data["pop"]["time"]["international"]["day"]["last_month"]: + ave_post_perday_international_last_month+=i +ave_post_perday_international_last_month=ave_post_perday_international_last_month/(33*7*12) + +ave_post_perday_international_last_three_month=0 +for i in data["pop"]["time"]["international"]["day"]["last_three_months"]: + ave_post_perday_international_last_three_month+=i +ave_post_perday_international_last_three_month=ave_post_perday_international_last_three_month/(99*7*12) + + + + + + + +############################ Sheet Data + + +num_image_national,num_posts_national,num_video_national=[[],[],[]],[[],[],[]],[[],[],[]] + +for i in national_company_name2: + k=-1 + for j in ["last_month","last_three_months","overal"]: + k+=1 + num_posts_national[k].append(len(data["information"][i]["analysis"]["time"]["analayzed_post_time"][j]["all_posts_type"])) + num_image_national[k].append(len(data["information"][i]["analysis"]["time"]["analayzed_post_time"][j]["image"])) + num_video_national[k].append(len(data["information"][i]["analysis"]["time"]["analayzed_post_time"][j]["video"])) + +sheet_data=pd.DataFrame(data={ + "Company":national_company_name_fa, + "Last Month Total Posts":num_posts_national[0], + "Last Month Image":num_image_national[0], + "Last Month Video":num_video_national[0], + "Last Three Months Total Posts":num_posts_national[1], + "Last Three Months Image":num_image_national[1], + "Last Three Months Video":num_video_national[1], + "Overal Total Posts":num_posts_national[2], + "Overal Image":num_image_national[2], + "Overal Video":num_video_national[2], + + }) + + + + + +num_image_national,num_posts_national,num_video_national=[[],[],[]],[[],[],[]],[[],[],[]] + +for i in international_company_name2: + k=-1 + for j in ["last_month","last_three_months","overal"]: + k+=1 + num_posts_national[k].append(len(data["information"][i]["analysis"]["time"]["analayzed_post_time"][j]["all_posts_type"])) + num_image_national[k].append(len(data["information"][i]["analysis"]["time"]["analayzed_post_time"][j]["image"])) + num_video_national[k].append(len(data["information"][i]["analysis"]["time"]["analayzed_post_time"][j]["video"])) + +sheet_1data=pd.DataFrame(data={ + "Company":international_company_name_fa, + "Last Month Total Posts":num_posts_national[0], + "Last Month Image":num_image_national[0], + "Last Month Video":num_video_national[0], + "Last Three Months Total Posts":num_posts_national[1], + "Last Three Months Image":num_image_national[1], + "Last Three Months Video":num_video_national[1], + "Overal Total Posts":num_posts_national[2], + "Overal Image":num_image_national[2], + "Overal Video":num_video_national[2], + + }) +del num_image_national,num_posts_national,num_video_national + + + + + + +########### ranks + + + +rank=[i for i in sheet3followers] +rank.sort() +eer=len(sheet3followers) +ranki=[(eer-rank.index(i)) for i in sheet3followers] +eer=len(sheet3_1followers) +rank=[i for i in sheet3_1followers] +rank.sort() +ranki_1=[(eer-rank.index(i)) for i in sheet3_1followers] +del rank + +#########3 number of posts analysed +number_posts_analysed=0 +number_posts_analysed_national=0 +number_posts_analysed_international=0 +max_national=0 +max_national_account="" +min_national=90000000 +min_national_account="" +max_international=0 +max_international_account="" +min_international=90000000 +min_international_account="" +for i in data["information"]: + if i in national_company_name2: + number_posts_analysed_national+=data["information"][i]["analysis"]["number_of_posts_analysed"] + if data["information"][i]["analysis"]["number_of_posts_analysed"]>=max_national: + max_national=data["information"][i]["analysis"]["number_of_posts_analysed"] + max_national_account=i + if data["information"][i]["analysis"]["number_of_posts_analysed"]<=min_national: + min_national=data["information"][i]["analysis"]["number_of_posts_analysed"] + min_national_account=i + else: + number_posts_analysed_international+=data["information"][i]["analysis"]["number_of_posts_analysed"] + if data["information"][i]["analysis"]["number_of_posts_analysed"]>=max_international: + max_international=data["information"][i]["analysis"]["number_of_posts_analysed"] + max_international_account=i + if data["information"][i]["analysis"]["number_of_posts_analysed"]<=min_international: + min_international=data["information"][i]["analysis"]["number_of_posts_analysed"] + min_international_account=i + + number_posts_analysed+=data["information"][i]["analysis"]["number_of_posts_analysed"] + +dash_1=pd.DataFrame(data={"خلاصه":["تعداد شرکت‌های داخلی مورد بررسی","تعداد شرکت‌های بین المللی مورد بررسی","تعداد پست های مورد بررسی","تعداد پست های شرکت‌های داخلی بررسی شده", + "تعداد پست‌های شرکت های بین المللی بررسی شده","میانگین تعداد پست‌های بررسی شده برای هر شرکت داخلی","میانگین تعداد پست های بررسی شده برای هر شرکت بین المللی", + "بیشترین تعداد پست های بررسی شده برای یک شرکت داخلی","حساب کاربری بیشترین تعداد پست های بررسی شده برای یک شرکت داخلی ", + "کم ترین میزان پست های بررسی شده برای یک شرکت داخلی","حساب کاربری کم ترین میزان پست های بررسی شده برای یک شرکت داخلی", + "بیشترین تعداد پست‌های بررسی شده برای یک شرکت بین المللی","حساب کاربری بیشترین تعداد پست‌های بررسی شده برای یک شرکت بین المللی", + "کم ترین تعداد پست های بررسی شده برای یک شرکت بین المللی","حساب کاربری کم ترین میزان پست های بررسی شده برای یک شرکت بین المللی" + ], + "تعداد":[19,12,number_posts_analysed,number_posts_analysed_national,number_posts_analysed_international,"{:.1f}".format(number_posts_analysed_national/19), + "{:.1f}".format(number_posts_analysed_international/12), + max_national,max_national_account,min_national,min_national_account,max_international,max_international_account,min_international,min_international_account + + ] + + }) + +del max_national,max_national_account,min_international,min_international_account,min_national,min_national_account,max_international,max_international_account + + + +if jkl: + + + ########## Sidebar + option1=["داشبورد","شرکت‌های داخلی","شرکت‌های بین المللی","آپارات","خلاصه"] + + option2_fa=["شبکه‌های اجتماعی","جایگاه در شبکه‌های اجتماعی","ماهیت پست ها","تحلیل پست ها","تحلیل هشتگ ها","تحلیل اموجی ها","تحلیل متن ها","محبوب ها","تحلیل محتوای پست‌ها","پیوند پست‌های محبوب","تحلیل میزان تعامل شرکت‌ها","زمان بارگذاری پست‌ها"] + option3_fa=["شبکه‌های اجتماعی","تعداد دنبال کنندگان","پسندیده شدن","نظرات","بازدید","مشارکت"] + option2=["Social Meidas","Popularities","Form of Posts","Posts Analysis","Hashtags Analysis","Emoji Analysis","Caption Analysis","Populars","Content Analysis","Popular Posts Link","Interaction Analysis","Posting Time"] + option3=["Social Medias","Followers","Like","Comment","View","Engagement"] + option_aparat=["افق کوروش","دیجی کالا","رفاه"] + select1=st.sidebar.selectbox("انتخاب نوع شرکت‌ها برای تحلیل",option1,key=1) + + st.title("تحلیل بر خط شبکه‌های اجتماعی\n مهدی احمدی فرد") + + + ##### Aparat + + if select1=="آپارات": + st.markdown(""" + در اینجا شما می‌توانید ویدیو‌های محبوب در آپارات را مشاهده نمایید. + """) + + select_apa=st.selectbox("شرکت را انتخاب کنید",option_aparat,key=29) + optionah=["Playlists","Populars"] + #select_optionah=st.sidebar.selectbox("Choose the info you want to see",optionah,key=229) + ip_aparat=["okclub","digikala","myrefah"] + insd=ip_aparat[option_aparat.index(select_apa)] + + st.title("دسته بندی ویدیو‌ها") + pllay=[i["title"].replace("‌"," ") for i in data["aparat"][insd]["playlist"]] + pllay=pd.DataFrame(data={"Playlist":pllay}) + AgGrid(pllay,theme="streamlit") + #if select_optionah==optionah[1]: + + + df=pd.DataFrame(data={ + "شرکت":select_apa, + "رتبه نخست": [f'1={data["aparat"][insd]["posts"][data["aparat"][insd]["sort_view"][0]]["frame"]}'], + "رتبه دوم":[f'2={data["aparat"][insd]["posts"][data["aparat"][insd]["sort_view"][1]]["frame"]}'], + "رتبه سوم":[f'3={data["aparat"][insd]["posts"][data["aparat"][insd]["sort_view"][2]]["frame"]}'], + "رتبه چهارم":[f'3={data["aparat"][insd]["posts"][data["aparat"][insd]["sort_view"][3]]["frame"]}'] + }) + for i in ["رتبه نخست","رتبه دوم","رتبه سوم","رتبه چهارم"]: + df[i]=df[i].apply(make_clickable) + df=df.to_html(escape=False) + st.header("برای مشاهده پست‌ها بر روی اعداد کلیک کنید") + st.write(df,unsafe_allow_html=True) + + st.title("مشاهده مستقیم ویدیو‌ها") + st.header("پر بازدید ترین ویدیو") + st.write(f'''