Spaces:
Sleeping
Sleeping
import pandas as pd | |
import streamlit as st | |
import base64 | |
from roadmapper.roadmap import Roadmap | |
from roadmapper.timelinemode import TimelineMode | |
import datetime | |
import re | |
from io import BytesIO | |
import json | |
def clear_rfp_data(): | |
st.session_state.clear() | |
def export(data): | |
# data_df = pd.DataFrame(st.session_state["user_stories_json"]) | |
data_df = pd.DataFrame(data) | |
csv_data = data_df.to_csv(index=False) | |
b64 = base64.b64encode(csv_data.encode()).decode() | |
href = f'<a href="data:file/csv;base64,{b64}" download="data.csv">Download CSV File</a>' | |
st.markdown(href, unsafe_allow_html=True) | |
def estimate_to_value(estimate): | |
if estimate == "XS": | |
return 2 | |
elif estimate == "S": | |
return 6 | |
elif estimate == "M": | |
return 12 | |
elif estimate == "L": | |
return 22 | |
elif estimate == "XL": | |
return 37 | |
else: | |
# Handle the case when the estimate is not one of the specified values | |
return "Invalid estimate" | |
def is_key_value_present(array_of_objects, key, value): | |
for obj in array_of_objects: | |
if key in obj and obj[key] == value: | |
return True | |
return False | |
def generate_roadmap_image(): | |
# Calculate the project start date (15 days from today) | |
project_start_date = datetime.datetime.now() + datetime.timedelta(days=15) | |
project_start_date_str = project_start_date.strftime("%Y-%m-%d") | |
roadmap = Roadmap(1400, 800, colour_theme="BLUEMOUNTAIN") | |
roadmap.set_title("Project Roadmap") | |
roadmap.set_subtitle(st.session_state["project_name"]) | |
roadmap.set_timeline(TimelineMode.MONTHLY, start=project_start_date_str, number_of_items=12) | |
group_index = 1 | |
milestone_index = 1 | |
data = st.session_state["roadmap_data_json"] | |
prev_phase_end_date = None | |
data = json.loads(st.session_state["roadmap_data_json"]) | |
for phase in data["phases"]: | |
group_name = f"{phase['name']} - {group_index}" | |
group = roadmap.add_group(group_name) | |
milestone_start_date = project_start_date if prev_phase_end_date is None else prev_phase_end_date | |
for milestone in phase["milestones"]: | |
task_name = f"milestone - {milestone_index}" | |
total_time_range = [int(num) for num in re.findall(r'\d+', milestone["totalTime"])] | |
total_working_days = sum(total_time_range) / 2 | |
average_duration = total_working_days / 5 * 7 | |
milestone_end_date = milestone_start_date + datetime.timedelta(days=average_duration) | |
print(milestone_start_date,milestone_end_date) | |
group.add_task(task_name, milestone_start_date.strftime("%Y-%m-%d"), milestone_end_date.strftime("%Y-%m-%d")) | |
milestone_start_date = milestone_end_date | |
milestone_index += 1 | |
prev_phase_end_date = milestone_end_date | |
group_index += 1 | |
roadmap.set_footer("Generated by Roadmapper") | |
roadmap.draw() | |
project_name = get_dynamic_filename() | |
roadmap.save(project_name) | |
st.download_button( | |
label="Download Roadmap Image", | |
data=open(project_name, "rb").read(), | |
key="download_roadmap", | |
file_name=project_name, | |
mime="image/png", | |
) | |
def get_binary_file_downloader_html(bin_file, file_label, button_label): | |
with st.spinner("Processing..."): | |
# Provide a download link for the image | |
bin_str = base64.b64encode(bin_file).decode() | |
href = f'<a href="data:application/octet-stream;base64,{bin_str}" download="{file_label}">{button_label}</a>' | |
return href | |
def get_dynamic_filename(): | |
project_name = st.session_state["project_name"] | |
current_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S") | |
filename = f"{project_name}_roadmap_{current_time}.png" | |
return filename |