Changing colour range in dropdown - dropdown

I am trying to create a choropleth with dropdown. I want to change colour scale with dropdown buttons, like min and max for each button. my recent scale is between 0 , 50 M. it makes sense for some buttons but for button A, it doesnt make any sense
thanks in advance
from urllib.request import urlopen import json with
urlopen("https://raw.githubusercontent.com/Babolius/project/62fef3b31fa9e34afb055e493de107d89a50a889/tr-cities-utf8.json")
as response:
id = json.load(response) import pandas as pd df = pd.read_csv("https://raw.githubusercontent.com/Babolius/project/main/komisyon5.csv",encoding
='utf8', dtype={"Toplam": int}) df.groupby(['ID']).sum()
import plotly.express as px
fig = px.choropleth_mapbox(df, geojson= id, locations= 'ID', color=
"Toplam",
color_continuous_scale="Viridis",
range_color=(0, 10000000),
mapbox_style="carto-darkmatter",
zoom=3, center = {"lat": 41.0902, "lon": 28.7129},
opacity=0.5,
)
dropdown_buttons =[{'label': 'A', 'method' : 'restyle', 'args': [{'z':
[df["A"]]}, {'visible': [True, False, False, False, False, False]},
{'title': 'A'}]},
{'label': 'B', 'method' : 'restyle', 'args': [{'z': [df["B"]]}, {'visible': [False, True, False, False, False, False]},
{'title': 'B'}]},
{'label': 'C', 'method' : 'restyle', 'args': [{'z': [df["C"]]}, {'visible': [False, False, True, False, False, False]},
{'title': 'C'}]},
{'label': 'D', 'method' : 'restyle', 'args': [{'z': [df["D"]]}, {'visible': [False, False, False, True, False, False]},
{'title': 'D'}]},
{'label': 'E', 'method' : 'restyle', 'args': [{'z': [df["E"]]}, {'visible': [False, False, False, False, True, False]},
{'title': 'E'}]},
{'label': 'Toplam', 'method' : 'restyle', 'args': [{'z': [df["Toplam"]]}, {'visible': [False, False, False, False,
False, True]}, {'title': 'Toplam'}]}]
fig.update_layout({'updatemenus':[{'type': 'dropdown', 'showactive':
True, 'active': 0, 'buttons': dropdown_buttons}]})
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}) fig.show()

It was easier than i thought
from urllib.request import urlopen
import json
with urlopen("https://raw.githubusercontent.com/Babolius/project/62fef3b31fa9e34afb055e493de107d89a50a889/tr-cities-utf8.json") as response:
id = json.load(response)
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/Babolius/project/main/komisyon5.csv",encoding ='utf8', dtype={"Toplam": int})
df.groupby(['ID']).sum()
import plotly.express as px
fig = px.choropleth_mapbox(df, geojson= id, locations= 'ID', color= "Toplam",
color_continuous_scale="Viridis",
color_discrete_sequence=(min, max),
mapbox_style="carto-darkmatter",
zoom=3, center = {"lat": 41.0902, "lon": 28.7129},
opacity=0.5,
)
dropdown_buttons =[{'label': 'A', 'method' : 'update', 'args': [{'z': [df["A"]]}, {'visible': [True, False, False, False, False, False]}, {'title': 'A'}]},
{'label': 'B', 'method' : 'update', 'args': [{'z': [df["B"]]}, {'visible': [False, True, False, False, False, False]}, {'title': 'B'}]},
{'label': 'C', 'method' : 'update', 'args': [{'z': [df["C"]]}, {'visible': [False, False, True, False, False, False]}, {'title': 'C'}]},
{'label': 'D', 'method' : 'update', 'args': [{'z': [df["D"]]}, {'visible': [False, False, False, True, False, False]}, {'title': 'D'}]},
{'label': 'E', 'method' : 'update', 'args': [{'z': [df["E"]]}, {'visible': [False, False, False, False, True, False]}, {'title': 'E'}]},
{'label': 'Toplam', 'method' : 'restyle', 'args': [{'z': [df["Toplam"]]}, {'visible': [False, False, False, False, False, True]}, {'title': 'Toplam'}]}]
fig.update_layout({'updatemenus':[{'type': 'dropdown', 'showactive': True, 'active': 0, 'buttons': dropdown_buttons}]})
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

Related

How can I get a DIFFERENT random float between 0 and 1 tested on each element of an array using a mask?

**This is the question for my homework: Write a function which simulates the DMS mutation process on one read using np.random.random to generate randomness according to a uniform distribution. Recall, with probability DMS_mutation_prob and eligible base acquires a DMS mutation.
The DMS_mutation_prob = 0.1
My function looks like this, where eligible_to_mutate is an np.array containing Boolean values - True at mutation eligible positions, False elsewhere, and DMS_mutation_prob is equal to 0.1**
def single_read_random_DMS_mutation_mask(eligible_to_mutate, DMS_mutation_prob):
mutation_profile = (eligible_to_mutate==True) & (np.random.random() <DMS_mutation_prob)
return mutation_profile
**
The only problem is that it choses one random number between 0 and 1 to test on all boolean values instead of a different one for each value.
How can I make it so that there's a different random float tested for each value?
When I tried this function where
eligible_to_mutate=
array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, True, True, True, True, True, False, True,
False, True, True, True, True, True, False, True, False,
True, False, False, False, False, True, True, True, True,
False, True, True, True, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False])
I either get the same eligible_to_mutate array:
array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, True, True, True, True, True, False, True,
False, True, True, True, True, True, False, True, False,
True, False, False, False, False, True, True, True, True,
False, True, True, True, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False])
**or
All false values**
array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False])

Multiple colspan in pdfmake

I need the below table structure in the pdf:
I am using pdfmake and tried but unable to achieve the exact structure.
Need some valuable help
I hope this will help you
var dd = {
content: [
{
alignment:'center',
table: {
widths: ['*','*','*','*','*','*','*',],
body: [
[
{
text: "",
border: [true, true, true, true],
},
{
colSpan:3,
text:'header 1',
border: [true, true, true, true],
},
{
text:'',
border: [true, true, true, true],
},
{
text: "",
border: [true, true, true, true],
},
{
colSpan:3,
text:'header 2',
border: [true, true, true, true],
},
{
text:'',
border: [true, true, true, true],
},
{
text:'',
border: [true, true, true, true],
},
],
[
{
text: "S.No.",
border: [true, true, true, true],
},
{
colSpan:3,
text:'item',
border: [true, true, true, true],
},
{
text:'',
border: [true, true, true, true],
},
{
text: "",
border: [true, true, true, true],
},
{
colSpan:3,
text:'data',
border: [true, true, true, true],
},
{
text:'',
border: [true, true, true, true],
},
{
text:'',
border: [true, true, true, true],
},
],
[
{
text: "1",
border: [true, true, true, true],
},
{
text:'item1',
border: [true, true, true, true],
},
{
text:'item2',
border: [true, true, true, true],
},
{
text: "item3",
border: [true, true, true, true],
},
{
text:'data1',
border: [true, true, true, true],
},
{
text:'data2',
border: [true, true, true, true],
},
{
text:'data3',
border: [true, true, true, true],
},
],
],
},
},
],
}

Split dictionary into multiple columns in SQL

The data fetched from API returns a dictionary format stored in a column, as below:
{"messaging": true, "newsletters": true, "ranking_coach": true, "sms_reminders": true, "birthday_reminders": true, "merchant_shiftplan": true}
{"messaging": false, "yext_sync": false, "marketplace": false, "newsletters": false, "ranking_coach": false, "sms_reminders": false, "sms_newsletters": false, "merchant_payment": true, "customer_feedback": true, "birthday_reminders": false, "merchant_dashboard": true, "merchant_shiftplan": false, "reserve_with_google": false, "sms_customer_confirmation": false, "individual_email_from_name": true, "appointment_location_customer": false}
{"messaging": false, "yext_sync": false, "marketplace": false, "newsletters": false, "ranking_coach": false, "sms_reminders": false, "sms_newsletters": false, "merchant_payment": true, "customer_feedback": true, "birthday_reminders": false, "merchant_dashboard": true, "merchant_shiftplan": false, "reserve_with_google": false, "sms_customer_confirmation": false, "individual_email_from_name": true, "appointment_location_customer": false}
{"messaging": false, "newsletters": false, "merchant_payment": false, "birthday_reminders": false, "merchant_shiftplan": false, "double_opt_in_required": false}
{"messaging": false, "yext_sync": false, "marketplace": false, "newsletters": false, "ranking_coach": false, "sms_reminders": false, "sms_newsletters": false, "merchant_payment": true, "customer_feedback": true, "birthday_reminders": false, "merchant_dashboard": true, "merchant_shiftplan": false, "reserve_with_google": false, "sms_customer_confirmation": false, "individual_email_from_name": true, "appointment_location_customer": false}
{"square": false, "insights": true, "api_token": false, "messaging": true, "wait_list": false, "yext_sync": false, "marketplace": false, "newsletters": true, "pdf_prefill": false, "free_product": false, "website_duda": false, "ranking_coach": false, "sms_reminders": true, "contact_widget": false, "online_booking": true, "sms_newsletters": false, "merchant_payment": false, "shared_customers": false, "customer_feedback": true, "external_services": false, "birthday_reminders": true, "merchant_dashboard": true, "merchant_shiftplan": false, "net_promoter_score": false, "new_booking_widget": true, "reserve_with_google": false, "file_download_widget": false, "automated_newsletters": true, "double_opt_in_required": false, "sms_customer_confirmation": false, "individual_email_from_name": false, "new_closingtime_background": false, "gdpr_marketing_opt_in_modal": false, "appointment_location_customer": false, "facebook_instagram_integration": false, "new_full_screen_booking_widget": true, "merchant_logo_on_customer_email": true, "show_all_branch_option_on_insights": false, "participating_account_notifications": false, "show_newsletter_non_subscriber_selection": false}
{"reporting": true, "newsletters": false, "merchant_payment": false, "customer_feedback": true, "reserve_with_google": true, "new_closingtime_background": true, "merchant_logo_on_customer_email": true}
{"messaging": false, "yext_sync": false, "marketplace": false, "newsletters": false, "ranking_coach": false, "sms_reminders": false, "sms_newsletters": false, "merchant_payment": true, "customer_feedback": true, "birthday_reminders": false, "merchant_dashboard": true, "merchant_shiftplan": false, "reserve_with_google": false, "sms_customer_confirmation": false, "individual_email_from_name": true, "appointment_location_customer": false}
{"messaging": false, "newsletters": false, "merchant_payment": false, "birthday_reminders": false, "merchant_shiftplan": false, "double_opt_in_required": false, "new_closingtime_background": true, "facebook_instagram_integration": true, "show_all_branch_option_on_insights": true, "show_newsletter_non_subscriber_selection": false}
{"sms_reminders": true, "customer_feedback": true, "merchant_dashboard": true, "reserve_with_google": false, "show_all_branch_option_on_insights": true}
An interesting point to note is that not all of the rows have the same features.
For instance, row#1 to row#5 start with messaging, row #6 start with square, row #7 start with reporting.
I would like to split this one column into multiple columns, where each column has only 1 feature.
Expected Output:
No. messaging newsletter ranking_coach sms_reminders
1 true true true true
2 false null null null
3 false null null null
..
6 null null null null
you can use json functionality in postgresql:
select
Jsoncol ->> 'messaging' messaging,
Jsoncol ->> 'newsletters' newsletters,
Jsoncol ->> 'ranking_coach' ranking_coach,
Jsoncol ->> 'sms_reminders' sms_reminders
from tablename
db<>fiddle here

Split column with Json values into multiple columns in Postgres

Calling DBeaver table columns:
Column Name # Data type Encoding
created_at 1 timestamp az64
column_with_json_values 22 varchar(2048) lzo
.
select column_with_json_values from table_name
column_with_json_values
{"messaging": true, "newsletters": true, "ranking_coach": true, "sms_reminders": true, "birthday_reminders": true, "merchant_shiftplan": true}
{"messaging": false, "yext_sync": false, "marketplace": false, "newsletters": false, "ranking_coach": false, "sms_reminders": false, "sms_newsletters": false, "merchant_payment": true, "customer_feedback": true, "birthday_reminders": false, "merchant_dashboard": true, "merchant_shiftplan": false, "reserve_with_google": false, "sms_customer_confirmation": false, "individual_email_from_name": true, "appointment_location_customer": false}
{"messaging": false, "yext_sync": false, "marketplace": false, "newsletters": false, "ranking_coach": false, "sms_reminders": false, "sms_newsletters": false, "merchant_payment": true, "customer_feedback": true, "birthday_reminders": false, "merchant_dashboard": true, "merchant_shiftplan": false, "reserve_with_google": false, "sms_customer_confirmation": false, "individual_email_from_name": true, "appointment_location_customer": false}
{"messaging": false, "newsletters": false, "merchant_payment": false, "birthday_reminders": false, "merchant_shiftplan": false, "double_opt_in_required": false}
{"messaging": false, "yext_sync": false, "marketplace": false, "newsletters": false, "ranking_coach": false, "sms_reminders": false, "sms_newsletters": false, "merchant_payment": true, "customer_feedback": true, "birthday_reminders": false, "merchant_dashboard": true, "merchant_shiftplan": false, "reserve_with_google": false, "sms_customer_confirmation": false, "individual_email_from_name": true, "appointment_location_customer": false}
{"square": false, "insights": true, "api_token": false, "messaging": true, "wait_list": false, "yext_sync": false, "marketplace": false, "newsletters": true, "pdf_prefill": false, "free_product": false, "website_duda": false, "ranking_coach": false, "sms_reminders": true, "contact_widget": false, "online_booking": true, "sms_newsletters": false, "merchant_payment": false, "shared_customers": false, "customer_feedback": true, "external_services": false, "birthday_reminders": true, "merchant_dashboard": true, "merchant_shiftplan": false, "net_promoter_score": false, "new_booking_widget": true, "reserve_with_google": false, "file_download_widget": false, "automated_newsletters": true, "double_opt_in_required": false, "sms_customer_confirmation": false, "individual_email_from_name": false, "new_closingtime_background": false, "gdpr_marketing_opt_in_modal": false, "appointment_location_customer": false, "facebook_instagram_integration": false, "new_full_screen_booking_widget": true, "merchant_logo_on_customer_email": true, "show_all_branch_option_on_insights": false, "participating_account_notifications": false, "show_newsletter_non_subscriber_selection": false}
{"reporting": true, "newsletters": false, "merchant_payment": false, "customer_feedback": true, "reserve_with_google": true, "new_closingtime_background": true, "merchant_logo_on_customer_email": true}
{"messaging": false, "yext_sync": false, "marketplace": false, "newsletters": false, "ranking_coach": false, "sms_reminders": false, "sms_newsletters": false, "merchant_payment": true, "customer_feedback": true, "birthday_reminders": false, "merchant_dashboard": true, "merchant_shiftplan": false, "reserve_with_google": false, "sms_customer_confirmation": false, "individual_email_from_name": true, "appointment_location_customer": false}
{"messaging": false, "newsletters": false, "merchant_payment": false, "birthday_reminders": false, "merchant_shiftplan": false, "double_opt_in_required": false, "new_closingtime_background": true, "facebook_instagram_integration": true, "show_all_branch_option_on_insights": true, "show_newsletter_non_subscriber_selection": false}
{"sms_reminders": true, "customer_feedback": true, "merchant_dashboard": true, "reserve_with_google": false, "show_all_branch_option_on_insights": true}
An interesting point to note is that not all of the rows have the same features. For instance, row#1 to row#5 start with messaging, row #6 start with square, row #7 start with reporting.
I would like to split this one column into multiple columns, where each column has only 1 feature.
Expected Output:
No. messaging newsletter ranking_coach sms_reminders
1 true true true true
2 false null null null
3 false null null null
..
6 null null null null
This is an example query on how to access Json properties, you can cast to JSONB and then access by using ->.
Some info on -> and ->>:
PostgreSQL provides two native operators -> and ->> to help you query JSON data.
The operator -> returns JSON object field as JSON. The operator ->> returns JSON object field as text.
with jsonvalue as (
select '{"messaging": true, "newsletters": true, "ranking_coach": true, "sms_reminders": true, "birthday_reminders": true, "merchant_shiftplan": true}'::jsonb as jsonvalues
)
select
jsonvalues -> 'messaging',
jsonvalues -> 'newsletters'
from jsonvalue;
this will result in your expected output if you adjust my example query on your case. Hope this helped.

numpy mask covers another mask

I have different masks from different shapes in an image. Since some of the shapes contain other shapes, I would like to check if a given mask covers another given mask. For instance consider the followings:
A=[True, True, True, True, True,
True, False, False, False, True,
True, False, False, False, True,
True, False, False, False, True,
True, True, True, True, True]
B=[False, False, False, False, False,
False, True, True, False, False,
False, True, True, False, False,
False, False, False, False, False,
False, False, False, False, False]
In a 5x5 image, A covers B. How can I check if A covers B?
EDIT:
A and B could also share some points and A still covers B:
A=[True, True, True, True, True,
True, False, False, False, True,
True, False, False, False, True,
True, False, False, False, True,
True, True, True, True, True]
B=[False, False, False, False, False,
True, True, True, False, False,
True, True, True, False, False,
False, False, False, False, False,
False, False, False, False, False]
We could fill holes for A to have a blob and then perform OR-ing with B. If the OR-ing results in the same array as the holes-filled A, it concludes A as the "cover". To fill holes, we can use SciPy's binary_fill_holes -
from scipy.ndimage.morphology import binary_fill_holes
Af = binary_fill_holes(A)
out = (Af == Af | binary_fill_holes(B)).all()
# or np.array_equal(Af, Af | binary_fill_holes(B))