File size: 7,183 Bytes
5026d87
51d9500
edfd5fc
51d9500
9c0df62
3ddfd7a
 
1219693
307452b
3ddfd7a
 
9c0df62
307452b
 
3ddfd7a
5026d87
0fa4ba3
5026d87
 
0fa4ba3
5026d87
 
 
 
 
 
 
 
0fa4ba3
8b1bf9d
5026d87
 
 
 
 
307452b
5026d87
307452b
5026d87
 
 
307452b
5026d87
307452b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5026d87
307452b
 
e26e986
307452b
 
 
 
 
 
 
5026d87
 
307452b
 
5026d87
 
 
 
307452b
 
e26e986
307452b
 
 
5026d87
 
 
307452b
5026d87
307452b
5026d87
307452b
5026d87
9c0df62
307452b
5026d87
 
 
 
 
 
 
 
 
 
e26e986
c47f550
5026d87
 
 
 
 
9c0df62
5026d87
9c0df62
5026d87
 
 
0fa4ba3
6e1191d
5026d87
6e1191d
 
 
 
 
 
 
 
 
 
 
9c0df62
 
6e1191d
 
 
 
 
 
 
 
0fa4ba3
6e1191d
307452b
5026d87
7f2d686
5026d87
 
 
7f2d686
04e24c5
 
 
 
5026d87
04e24c5
7f2d686
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Data Visualization - Final Project (Viz for Experts)

# Contributors - Harshi, Sharanya, Jeenal


import streamlit as st
import altair as alt
import pandas as pd
import pycountry
from vega_datasets import data
 
st.write('Group 14 - Harshi, Sharanya & Jeenal')
 
st.title('World Bank Contracts Analysis')

st.write('This dashboard provides an in-depth analysis of how these contracts are distributed across countries, their trends over time and potential correlations between key metrics. Dive in to uncover meaningful patterns that reflect the impact of these investments globally.')

# Dataset Description
st.write('This analysis uses data from **World Bank Contract Awards**, detailing information about contracts under Investment Project Financing (IPF). It includes attributes such as country, fiscal year, contract numbers and more. By examining these attributes, we aim to highlight the distribution, trends and interdependencies in the global investment landscape.')

st.write("**Key Attributes of the Dataset:**")
st.write("""
- **Borrower Country / Economy**: The country or economy receiving the contract.
- **Fiscal Year**: The year the contract was signed, allowing for trend analysis.
- **WB Contract Number**: Unique identifier for each contract.
- **Contract Amount**: The financial value of the contract.
- **Procurement Method**: The method used for awarding the contract.
""")

st.write('Dataset is 99 MB, large enough for us to upload it on GitHub.')
# Reading Main Data
url = "contract_awards_in_investment_project_financing_22-11-2024.csv"
df = pd.read_csv(url, parse_dates=['As of Date', 'Fiscal Year', 'Contract Signing Date'], date_format={'As of Date': '%Y-%m-%d', 'Contract Signing Date': '%Y-%m-%d'})
df['Fiscal Year'] = df['Fiscal Year'].dt.year
# st.write(df.head(10))

df['Fiscal Year'] = df['Fiscal Year'].astype(int)

# Used for time-series plot
chart_data = df.groupby(['Borrower Country / Economy', 'Fiscal Year'])['WB Contract Number'].count()
# st.write(chart_data.head())

# Plot 1 -World map plot

@st.cache_data
def get_country_data():
    # Mapping numeric codes to country names
    country_data = []
    for country in pycountry.countries:
        try:
            country_data.append({
                'id': int(country.numeric),
                'name': country.name
            })
        except:
            continue
    return pd.DataFrame(country_data)

countries = alt.topo_feature(data.world_110m.url, 'countries')
country_df = get_country_data()
# st.write(country_df.head(10))

# Interactive selection tool initialization
selection = alt.selection_single(fields=['name'], empty='none')

# World Map with Interactions
map_chart = alt.Chart(countries).mark_geoshape(
    stroke='white'
).transform_lookup(
    lookup='id',
    from_=alt.LookupData(country_df, 'id', ['name'])
).transform_filter(
    alt.FieldOneOfPredicate(field='name', oneOf=list(df['Borrower Country / Economy'].unique()))
).encode(
    tooltip='name:N',
    color=alt.condition(
        selection,
        alt.value('green'),
        alt.value('lightgray')),
).properties(
    width=900,
    height=400
).project('naturalEarth1').add_selection(selection)


# Plot 2 - Time-series plot
merged_data = pd.merge(chart_data.reset_index(), country_df, left_on='Borrower Country / Economy', right_on='name', how='left')
# st.write(merged_data.head())

st.header('Trend of contracts acquired by country in the past years')

st.write('This interactive map highlights the countries that have received World Bank contracts. By hovering over a country, you can explore its name and status. This visualization provides an overview of global contract distribution, emphasizing regions with significant activity.')

# Prompt for selecting country
st.write("Hover over a country to see its contract data over time")

if selection != 'none':
    line_plot = alt.Chart(merged_data).mark_line().encode(
        x=alt.X('Fiscal Year:N', axis=alt.Axis(title='Fiscal Year')),
        y=alt.Y('WB Contract Number:Q', axis=alt.Axis(title='Total Contracts')),
        # color=
        tooltip=['Fiscal Year', 'WB Contract Number']
    ).transform_filter(
        selection
    ).properties(
        title=f'Total Contracts per Fiscal Year',
        width=400,
        height=300
    )
    final_chart = map_chart & line_plot

    st.altair_chart(final_chart, use_container_width=True)
else:
    st.altair_chart(map_chart, use_container_width=True)
    st.write('Choose a country to learn more about contract trends')
    


# Plot 3 - Correlation plot
numeric_columns = df.select_dtypes(include=['float64', 'int64']).columns
st.header("Correlation Analysis")
st.write('This section allows you to investigate the relationships between numeric attributes in the dataset. For example, examining correlations between **Contract Amount** and **Procurement Method Frequency** can provide insights into procurement practices and financial strategies.')

col1 = st.selectbox("Select First Numeric Attribute", numeric_columns, index=0)
col2 = st.selectbox("Select Second Numeric Attribute", numeric_columns, index=1)

correlation_value = df[col1].corr(df[col2])
st.write(f"**Correlation between {col1} and {col2}: {correlation_value:.2f}**")

correlation_plot = (
    alt.Chart(df)
    .mark_circle(size=60)
    .encode(
        x=alt.X(f"{col1}:Q", title=col1, scale=alt.Scale(zero=False)),
        y=alt.Y(f"{col2}:Q", title=col2, scale=alt.Scale(zero=False)),
        color="Region:N",  # Color by region for additional context
        tooltip=["Project Name", "Supplier", col1, col2],
    )
    .properties(
        title=f"Correlation Plot: {col1} vs. {col2}",
        width=600,
        height=400
    )
)
st.altair_chart(correlation_plot, use_container_width=True)

# Plot 3 write-up
st.write('The correlation plot allows experts to explore relationships between different numeric variables in the dataset. For instance, examining the correlation between Contract Amount and Procurement Method Frequency can reveal patterns in procurement practices. A strong correlation might indicate certain procurement methods are associated with higher or lower contract values, providing insights into efficiency and strategy. Users can select specific attributes to analyze and dynamically visualize how they interact across regions and industries.')

# Contextualization write-up
st.header('Contextualization')
st.write('Contextual Dataset')
st.write('World Bank Development Indicators by Industry')
st.write('Link: https://databank.worldbank.org/source/world-development-indicators')
st.write('Why Useful: This dataset includes industry-specific GDP contributions and growth metrics for different countries. Integrating it with contract award data can help analyze whether investments align with industry needs or economic potential, enabling an evaluation of their effectiveness.')
st.write('Additional Insight')
st.write('The correlation analysis combined with the contextual dataset could provide narratives such as:')
st.write('How contract investments influence specific industries.')
st.write('Patterns in procurement methods tied to economic growth in particular regions or industries.')