Blame view

src/core/pyros_django/scientific_program/functions.py 11.1 KB
5a434264   Alexis Koralewski   New version of Sc...
1
2
3
4
from common.models import Period
from dateutil.relativedelta import relativedelta

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

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

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

    if previous_period is not None:
f97bf756   Alexis Koralewski   Change name displ...
67
68
        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>\
d0aa130b   Alexis Koralewski   reworking timelin...
69
        <text x="12%" y="12%" fontsize="2em" fill="black">Exploitation</text>'
e00964fc   Alexis Koralewski   new version of ti...
70
71
        #<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...
72
        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...
73
74

    if current_period is not None:
f97bf756   Alexis Koralewski   Change name displ...
75
76
77
        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>\
d0aa130b   Alexis Koralewski   reworking timelin...
78
        <text x="32%" y="42%" fontsize="2em" fill="red">Exploitation</text>'
e00964fc   Alexis Koralewski   new version of ti...
79
80
        #<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...
81
        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...
82
83

    if future_period is not None:
d0aa130b   Alexis Koralewski   reworking timelin...
84
85
86
        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...
87
88
        #<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...
89
        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...
90
91
92
    
    return svg_content

077d5a23   Alexis Koralewski   adding science th...
93
94
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>\
d0aa130b   Alexis Koralewski   reworking timelin...
95
        <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...
96
        <text x="12%" y="65%" fontsize="2em" fill="black">Proposal submission</text>'
5a434264   Alexis Koralewski   New version of Sc...
97

077d5a23   Alexis Koralewski   adding science th...
98
    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...
99
        <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...
100
        <text x="32%" y="65%" fontsize="2em" fill="black">Evaluation</text>'
5a434264   Alexis Koralewski   New version of Sc...
101
    
077d5a23   Alexis Koralewski   adding science th...
102
    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...
103
        <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...
104
105
106
107
108
        <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...
109
    information_start_date = period.start_date + relativedelta(days=-10)
077d5a23   Alexis Koralewski   adding science th...
110
111
112
    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...
113
114
        <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...
115
116
        <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...
117
118
    proposal_svg += "</svg>"
    return proposal_svg