Blame view

src/core/pyros_django/scp_mgmt/functions.py 11 KB
5a434264   Alexis Koralewski   New version of Sc...
1
2
3
from dateutil.relativedelta import relativedelta

def get_svg_timeline(previous_period,current_period,future_period):
d0aa130b   Alexis Koralewski   reworking timelin...
4
    svg_content = '<svg id="detail_svg" width="80vw" height="10vh">'
5a434264   Alexis Koralewski   New version of Sc...
5
6
7
8
    svg_previous_period = ""
    svg_current_period = ""
    svg_future_period = ""
    if previous_period is not None:
d0aa130b   Alexis Koralewski   reworking timelin...
9
10
11
        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>'
5a434264   Alexis Koralewski   New version of Sc...
12
            #<text x="20%" y="15%" fontsize="2em" fill="black">{current_period.end_date.strftime("%d/%m/%Y")}</text>\
d0aa130b   Alexis Koralewski   reworking timelin...
13
14
15
16
17
        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>"
5a434264   Alexis Koralewski   New version of Sc...
18
    
2a529078   Alexis Koralewski   Fix some issues f...
19
20
21
22
23
24
25
26
27
    # 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>"
5a434264   Alexis Koralewski   New version of Sc...
28
    if current_period is not None:
2a529078   Alexis Koralewski   Fix some issues f...
29
        proposal_current_period = f'<rect id="proposal_current_period" x="10%" y=0 width="20%" height="60%" style="fill:silver;stroke-width:1"></rect>\
d0aa130b   Alexis Koralewski   reworking timelin...
30
            <text class="date_text" x="5%" y="75%" fontsize="2em" fill="black">{current_period.submission_start_date.strftime("%d/%m/%Y")}</text>\
5a434264   Alexis Koralewski   New version of Sc...
31
32
            <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>\
d0aa130b   Alexis Koralewski   reworking timelin...
33
34
        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>\
5a434264   Alexis Koralewski   New version of Sc...
35
36
            <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>\
d0aa130b   Alexis Koralewski   reworking timelin...
37
38
39
        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>\
5a434264   Alexis Koralewski   New version of Sc...
40
41
            <text x="52%" y="37%" fontsize="2em" fill="white">Private data access</text>'

17a88d97   Alexis Koralewski   reworking name fo...
42
        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>"
5a434264   Alexis Koralewski   New version of Sc...
43
    if future_period is not None:
2a529078   Alexis Koralewski   Fix some issues f...
44
        proposal_future_period = f'<rect id="proposal_future_period" x="10%" y=0% width="40%" height="60%" style="fill:silver;stroke-width:1"></rect>\
3921a0a3   Alexis Koralewski   Shifting proposal...
45
            <text class="date_text" x="5%" y="75%" fontsize="2em" fill="black">{future_period.submission_start_date.strftime("%d/%m/%Y")}</text>\
d0aa130b   Alexis Koralewski   reworking timelin...
46
            <text x="32%" y="37%" fontsize="2em" fill="white">SP Proposal</text>'
5a434264   Alexis Koralewski   New version of Sc...
47
48
            
            #<text x="40%" y="75%" fontsize="2e" fill="black">{future_period.start_date.strftime("%d/%m/%Y")}</text>\
d0aa130b   Alexis Koralewski   reworking timelin...
49
        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>\
864952f0   Alexis Koralewski   Hide Period timel...
50
51
            <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>\
d0aa130b   Alexis Koralewski   reworking timelin...
52
            <text x="52%" y="37%" fontsize="2em" fill="black">Exploitation</text>'
5a434264   Alexis Koralewski   New version of Sc...
53
54
        #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>"
17a88d97   Alexis Koralewski   reworking name fo...
55
        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>"
5a434264   Alexis Koralewski   New version of Sc...
56
57
58
59
    svg_content += "</svg>"
    return svg_content

def get_global_svg_timeline(previous_period,current_period,future_period):
d0aa130b   Alexis Koralewski   reworking timelin...
60
    svg_content = '<svg id="global_svg" width="80vw" height="20vh">'
5a434264   Alexis Koralewski   New version of Sc...
61
62
63
64
65
    svg_previous_period = ""
    svg_current_period = ""
    svg_future_period = ""

    if previous_period is not None:
2a529078   Alexis Koralewski   Fix some issues f...
66
        previous_period_svg = f'<rect class="previous_period" x="10%" y=0% width="20%" height="20%" style="fill:rgb(230, 244, 177);stroke-width:1"></rect>\
f97bf756   Alexis Koralewski   Change name displ...
67
        <rect class="previous_period" x="25%" y=0 width="40%" height="20%" style="fill:blue; stroke-width:1"></rect>\
d0aa130b   Alexis Koralewski   reworking timelin...
68
        <text x="12%" y="12%" fontsize="2em" fill="black">Exploitation</text>'
e00964fc   Alexis Koralewski   new version of ti...
69
70
        #<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>\
f97bf756   Alexis Koralewski   Change name displ...
71
        svg_content+=f'<text x="0%" y="12%" fontsize="2em" fill="black" class="previous_period">Previous (P{current_period.id})</text>' + previous_period_svg
5a434264   Alexis Koralewski   New version of Sc...
72
73

    if current_period is not None:
f97bf756   Alexis Koralewski   Change name displ...
74
        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>\
2a529078   Alexis Koralewski   Fix some issues f...
75
        <rect class="current_period" x="10%" y=30% width="20%" height="20%" style="fill:silver;stroke-width:1"></rect>\
f97bf756   Alexis Koralewski   Change name displ...
76
        <rect class="current_period" x=45% y=30% width="20%" height="20%" style="fill:rgb(192,192,220);stroke-width:1"></rect>\
d0aa130b   Alexis Koralewski   reworking timelin...
77
        <text x="32%" y="42%" fontsize="2em" fill="red">Exploitation</text>'
e00964fc   Alexis Koralewski   new version of ti...
78
79
        #<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>\
f97bf756   Alexis Koralewski   Change name displ...
80
        svg_content+=f'<text x="0%" y="42%" fontsize="2em" fill="black"  class="current_period" >Current (P{current_period.id})</text>' + current_period_svg
5a434264   Alexis Koralewski   New version of Sc...
81
82

    if future_period is not None:
d0aa130b   Alexis Koralewski   reworking timelin...
83
84
85
        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>'
e00964fc   Alexis Koralewski   new version of ti...
86
87
        #<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>\
f97bf756   Alexis Koralewski   Change name displ...
88
        svg_content+=f'<text x="0%" y="72%" fontsize="2em" fill="black" class="future_period">Future (P{future_period.id})</text>' + future_period_svg
5a434264   Alexis Koralewski   New version of Sc...
89
90
91
    
    return svg_content

077d5a23   Alexis Koralewski   adding science th...
92
def get_proposal_svg_timeline(period,period_name):
2a529078   Alexis Koralewski   Fix some issues f...
93
    proposal_svg = f'<svg id="proposal_detail" width="80vw" height="10vh"> <rect x="10%" y=40% width="19.9%" height="40%" style="fill:silver;stroke-width:1"></rect>\
d0aa130b   Alexis Koralewski   reworking timelin...
94
        <text class="date_text" x="5%" y="100%" fontsize="2em" fill="black">{period.submission_start_date.strftime("%d/%m/%Y")}</text>\
077d5a23   Alexis Koralewski   adding science th...
95
        <text x="12%" y="65%" fontsize="2em" fill="black">Proposal submission</text>'
5a434264   Alexis Koralewski   New version of Sc...
96

077d5a23   Alexis Koralewski   adding science th...
97
    proposal_svg += f'<rect id="proposal_detail" x="25%" y=40% width="19.9%" height="40%" style="fill:silver;stroke-width:1"></rect>\
d0aa130b   Alexis Koralewski   reworking timelin...
98
        <text class="date_text" x="25%" y="100%" fontsize="2em" fill="black">{period.submission_end_date.strftime("%d/%m/%Y")}</text>\
077d5a23   Alexis Koralewski   adding science th...
99
        <text x="32%" y="65%" fontsize="2em" fill="black">Evaluation</text>'
5a434264   Alexis Koralewski   New version of Sc...
100
    
077d5a23   Alexis Koralewski   adding science th...
101
    proposal_svg += f'<rect id="proposal_detail" x="45%" y=40% width="19.9%" height="40%" style="fill:silver;stroke-width:1"></rect>\
d0aa130b   Alexis Koralewski   reworking timelin...
102
        <text class="date_text" x="45%" y="100%" fontsize="2em" fill="black">{period.unit_pi_validation_start_date.strftime("%d/%m/%Y")}</text>\
077d5a23   Alexis Koralewski   adding science th...
103
104
105
106
107
        <text x="52%" y="65%" fontsize="2em" fill="black">Validation</text>'
    if period_name == "current":
        x2 = "25%"
    else:
        x2 = "45%"
5a434264   Alexis Koralewski   New version of Sc...
108
    information_start_date = period.start_date + relativedelta(days=-10)
077d5a23   Alexis Koralewski   adding science th...
109
110
111
    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" />\
d0aa130b   Alexis Koralewski   reworking timelin...
112
113
        <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>\
077d5a23   Alexis Koralewski   adding science th...
114
115
        <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>'
5a434264   Alexis Koralewski   New version of Sc...
116
117
    proposal_svg += "</svg>"
    return proposal_svg