functions.py 11.1 KB
from common.models import Period
from dateutil.relativedelta import relativedelta

def get_svg_timeline(previous_period,current_period,future_period):
    svg_content = '<svg id="detail_svg" width="80vw" height="10vh">'
    svg_previous_period = ""
    svg_current_period = ""
    svg_future_period = ""
    if previous_period is not None:
        exploit_previous_period = f'<rect id="exploit_previous_period" x="5%" y=0 width="20%" height="60%" style="fill:rgb(230, 244, 177);stroke-width:1"></rect>\
            <text class="date_text" x="5%" y="90%" fontsize="2em" fill="black">{previous_period.start_date.strftime("%d/%m/%Y")}</text>\
            <text x="15%" y="35%" fontsize="2em" fill="black">Exploitation</text>'
            #<text x="20%" y="15%" fontsize="2em" fill="black">{current_period.end_date.strftime("%d/%m/%Y")}</text>\
        data_access_previous_period = f'<rect id="data_access_previous_period" x=25% y=0 width="40%" height="60%" style="fill:blue; stroke-width:1"></rect>\
            <text class="date_text" x="25%" y="90%" fontsize="2em"  fill="black">{previous_period.end_date.strftime("%d/%m/%Y")}</text>\
            <text class="date_text" x="60%" y="90%" fontsize="2em"  fill="black">{previous_period.property_of_data_end_date.strftime("%d/%m/%Y")}</text>\
            <text x="32%" y="35%" fontsize="2em" fill="white">Private data access</text>'
        svg_content+=f'<svg id="detail_previous_period"><text x="0%" y="35%" fontsize="2em" fill="black">Previous(P{current_period.id})</text>' +exploit_previous_period +"\n"+ data_access_previous_period + "</svg>"
    
    exploit_previous_period = f'<rect id="exploit_previous_period" x="5%" y=0 width="20%" height="60%" style="fill:rgb(230, 244, 177);stroke-width:1"></rect>\
            <text class="date_text" x="5%" y="90%" fontsize="2em" fill="black">{current_period.start_date.strftime("%d/%m/%Y")}</text>\
            <text x="15%" y="35%" fontsize="2em" fill="black">Exploitation</text>'
            #<text x="20%" y="15%" fontsize="2em" fill="black">{current_period.end_date.strftime("%d/%m/%Y")}</text>\
    data_access_previous_period = f'<rect id="data_access_previous_period" x=25% y=0 width="40%" height="60%" style="fill:blue; stroke-width:1"></rect>\
        <text class="date_text" x="25%" y="90%" fontsize="2em"  fill="black">{current_period.end_date.strftime("%d/%m/%Y")}</text>\
        <text class="date_text" x="60%" y="90%" fontsize="2em"  fill="black">{current_period.property_of_data_end_date.strftime("%d/%m/%Y")}</text>\
        <text x="32%" y="35%" fontsize="2em" fill="white">Private data access</text>'
    svg_content+=f'<svg id="detail_previous_period"><text x="0%" y="35%" fontsize="2em" fill="black">Previous (P{current_period.id})</text>' +exploit_previous_period +"\n"+ data_access_previous_period + "</svg>"
    if current_period is not None:
        proposal_current_period = f'<rect id="proposal_current_period" x="5%" y=0 width="20%" height="60%" style="fill:silver;stroke-width:1"></rect>\
            <text class="date_text" x="5%" y="75%" fontsize="2em" fill="black">{current_period.submission_start_date.strftime("%d/%m/%Y")}</text>\
            <text x="15%" y="37%" fontsize="2em" fill="white">SP Proposal</text>'
            #<text x="20%" y="45%" fontsize="2e" fill="black">{current_period.start_date.strftime("%d/%m/%Y")}</text>\
        exploit_current_period = f'<rect id="exploit_current_period" x=25% y=0% width="20%" height="60%" style="fill:rgb(230, 244, 177);stroke-width:1"></rect>\
            <text class="date_text" x="25%" y="75%" fontsize="2em" fill="black">{current_period.start_date.strftime("%d/%m/%Y")}</text>\
            <text x="32%" y="37%" fontsize="2em" fill="red">Exploitation</text>'
            #<text x="40%" y="45%" fontsize="2em" fill="black">{current_period.end_date.strftime("%d/%m/%Y")}</text>\
        data_access_current_period = f'<rect id="data_access_current_period" x=45% y=0% width="20%" height="60%" style="fill:rgb(192,192,220);stroke-width:1"></rect>\
            <text class="date_text" x="45%" y="75%" fontsize="2em" fill="black">{current_period.end_date.strftime("%d/%m/%Y")}</text>\
            <text class="date_text" x="60%" y="75%" fontsize="2em" fill="black">{current_period.property_of_data_end_date.strftime("%d/%m/%Y")}</text>\
            <text x="52%" y="37%" fontsize="2em" fill="white">Private data access</text>'

        svg_content += "\n"+ f'<svg id="detail_current_period"><text x="0%" y="38%" fontsize="2em" fill="black">Current (P{current_period.id})</text>' + proposal_current_period + "\n" + exploit_current_period + "\n" + data_access_current_period + "</svg>"
    if future_period is not None:
        proposal_future_period = f'<rect id="proposal_future_period" x="5%" y=0% width="40%" height="60%" style="fill:silver;stroke-width:1"></rect>\
            <text class="date_text" x="5%" y="75%" fontsize="2em" fill="black">{future_period.submission_start_date.strftime("%d/%m/%Y")}</text>\
            <text x="32%" y="37%" fontsize="2em" fill="white">SP Proposal</text>'
            
            #<text x="40%" y="75%" fontsize="2e" fill="black">{future_period.start_date.strftime("%d/%m/%Y")}</text>\
        exploit_future_period = f'<rect id="exploit_future_period" x=45% y=0% width="20%" height="60%" style="fill:rgb(230, 244, 177);stroke-width:1"></rect>\
            <text class="date_text" x="45%" y="75%" fontsize="2em" fill="black">{future_period.start_date.strftime("%d/%m/%Y")}</text>\
            <text class="date_text" x="60%" y="75%" fontsize="2em" fill="black">{future_period.end_date.strftime("%d/%m/%Y")}</text>\
            <text x="52%" y="37%" fontsize="2em" fill="black">Exploitation</text>'
        #grey_rect = '<rect id="exploit_future_period" x=5% y=60% width="20%" height="10%" style="fill:silver;stroke-width:1"></rect>'
        #svg_content += "\n"+ f'<svg id="detail_future_period"><text x="0%" y="68%" fontsize="2em" fill="black">Future(P{future_period.id})</text>' + grey_rect+ "\n"+  proposal_future_period + "\n" + exploit_future_period + "</svg>"
        svg_content += "\n"+ f'<svg id="detail_future_period"><text x="0%" y="37%" fontsize="2em" fill="black">Future (P{future_period.id})</text>' + "\n"+  proposal_future_period + "\n" + exploit_future_period + "</svg>"
    svg_content += "</svg>"
    return svg_content

def get_global_svg_timeline(previous_period,current_period,future_period):
    svg_content = '<svg id="global_svg" width="80vw" height="20vh">'
    svg_previous_period = ""
    svg_current_period = ""
    svg_future_period = ""

    if previous_period is not None:
        previous_period_svg = f'<rect class="previous_period" x="5%" y=0% width="20%" height="20%" style="fill:rgb(230, 244, 177);stroke-width:1"></rect>\
        <rect class="previous_period" x="25%" y=0 width="40%" height="20%" style="fill:blue; stroke-width:1"></rect>\
        <text x="12%" y="12%" fontsize="2em" fill="black">Exploitation</text>'
        #<text class="date_text" x="5%" y="15%" fontsize="2em" fill="black">{previous_period.start_date.strftime("%d/%m/%Y")}</text>\
        #<text class="date_text" x="20%" y="15%" fontsize="2e" fill="black">{previous_period.end_date.strftime("%d/%m/%Y")}</text>\
        svg_content+=f'<text x="0%" y="12%" fontsize="2em" fill="black" class="previous_period">Previous (P{current_period.id})</text>' + previous_period_svg

    if current_period is not None:
        current_period_svg = f'<rect class="current_period" x="25%" y=30% width="20%" height="20%" style="fill:rgb(230, 244, 177);stroke-width:1"></rect>\
        <rect class="current_period" x="5%" y=30% width="20%" height="20%" style="fill:silver;stroke-width:1"></rect>\
        <rect class="current_period" x=45% y=30% width="20%" height="20%" style="fill:rgb(192,192,220);stroke-width:1"></rect>\
        <text x="32%" y="42%" fontsize="2em" fill="red">Exploitation</text>'
        #<text class="date_text" x="25%" y="45%" fontsize="2em" fill="black">{current_period.start_date.strftime("%d/%m/%Y")}</text>\
        #<text class="date_text" x="40%" y="45%" fontsize="2e" fill="black">{current_period.end_date.strftime("%d/%m/%Y")}</text>\
        svg_content+=f'<text x="0%" y="42%" fontsize="2em" fill="black"  class="current_period" >Current (P{current_period.id})</text>' + current_period_svg

    if future_period is not None:
        future_period_svg = f'<rect class="future_period" x="45%" y=60% width="20%" height="20%" style="fill:rgb(230, 244, 177);stroke-width:1"></rect>\
        <rect class="future_period" x="5%" y=60% width="40%" height="20%" style="fill:silver;stroke-width:1"></rect>\
        <text x="52%" y="72%" fontsize="2em" fill="black">Exploitation</text>'
        #<text class="date_text" x="45%" y="75%" fontsize="2em" fill="black">{future_period.start_date.strftime("%d/%m/%Y")}</text>\
        #<text class="date_text" x="60%" y="75%" fontsize="2e" fill="black">{future_period.end_date.strftime("%d/%m/%Y")}</text>\
        svg_content+=f'<text x="0%" y="72%" fontsize="2em" fill="black" class="future_period">Future (P{future_period.id})</text>' + future_period_svg
    
    return svg_content

def get_proposal_svg_timeline(period,period_name):
    proposal_svg = f'<svg id="proposal_detail" width="80vw" height="10vh"> <rect x="5%" y=40% width="19.9%" height="40%" style="fill:silver;stroke-width:1"></rect>\
        <text class="date_text" x="5%" y="100%" fontsize="2em" fill="black">{period.submission_start_date.strftime("%d/%m/%Y")}</text>\
        <text x="12%" y="65%" fontsize="2em" fill="black">Proposal submission</text>'

    proposal_svg += f'<rect id="proposal_detail" x="25%" y=40% width="19.9%" height="40%" style="fill:silver;stroke-width:1"></rect>\
        <text class="date_text" x="25%" y="100%" fontsize="2em" fill="black">{period.submission_end_date.strftime("%d/%m/%Y")}</text>\
        <text x="32%" y="65%" fontsize="2em" fill="black">Evaluation</text>'
    
    proposal_svg += f'<rect id="proposal_detail" x="45%" y=40% width="19.9%" height="40%" style="fill:silver;stroke-width:1"></rect>\
        <text class="date_text" x="45%" y="100%" fontsize="2em" fill="black">{period.unit_pi_validation_start_date.strftime("%d/%m/%Y")}</text>\
        <text x="52%" y="65%" fontsize="2em" fill="black">Validation</text>'
    if period_name == "current":
        x2 = "25%"
    else:
        x2 = "45%"
    information_start_date = period.start_date + relativedelta(days=-10)
    proposal_svg += f'<rect id="proposal_detail" x="65%" y=40% width="19.9%" height="40%" style="fill:silver;stroke-width:1"></rect>\
        <line x1="5%" y1="40%" x2="5%" y2="0%" stroke-dasharray="5,5" style="stroke:rgb(255,0,0);stroke-width:2" />\
        <line x1="85%" y1="40%" x2={x2} y2="0%" stroke-dasharray="5,5" style="stroke:rgb(255,0,0);stroke-width:2" />\
        <text class="date_text" x="65%" y="100%" fontsize="2em" fill="black">{information_start_date.strftime("%d/%m/%Y")}</text>\
        <text class="date_text" x="80%" y="100%" fontsize="2em" fill="black">{period.start_date.strftime("%d/%m/%Y")}</text>\
        <text x="72%" y="65%" fontsize="2em" fill="black">Notification</text>'
    proposal_svg +=f'<text x="0%" y="65%" fontsize="2em" fill="black">Period (P{period.id})</text>'
    proposal_svg += "</svg>"
    return proposal_svg