Solar Generation 2

We have a text file with information about the power generated by a solar plant. Each line contains the data corresponding to a solar panel. It includes the following data separated by ';' :

  • the group id of the group the solar panel belongs to

  • its location inside the group

  • its status (whether is 'on' or 'off')

  • a sequence of measures of the power generated by that panel at different times: each measure is either a float value, or the string '*' if the measurement system failed.

For example, see the first 5 lines of (first 5 panels) of the file solargen_data.txt:

gA;1-15;on;3.5;2.5;4.0;*;7.0;3.2;4.0
gA;2-16;off;0.0;0.2;0.0;*;0.3;*
gA;3-17;on;3.0;3.3;4.4;2.0;7.0;3.0;4.0;5.0
gB;3-11;on;2.3;3.5
gB;1-13;on;*;3.9

Notice that the panel '3-15' in group 'gA' generated \(3.5+2.5+4.0+7.0+3.2+4.0 = 24.2\) kWh, and the total generated by group 'gA' is \(= 55.9\) kWh ( \(24.2\) from panel '3-15' plus \(31.7\) from panel '3-17', and nothing from panel '3-16' since it is off). solar panel You are required to implement the following functions in the module solargen2.py (file solargen2.py):

Note

First function weights 75% and second 25%.

The first function is

solargen_sum(fnamein, fnameout)

such that given

two str with the names of two files, fnamein a file with data from a solar generation plant as described above, and fnameout a non-existing file,

writes a file named fnameout which contains a line for each line in the input file that is 'on', with the follwing information for each line:

  • the group id

  • the location

  • the number of measures of that location (those that are not an '*')

  • the power produced by that solar panel (the sum of all its measures that not an '*')

For instance, the call solargen_sum('solargen_data.txt', 'solargen_sum_out.txt') should write the file solargen_sum_out.txt with the following info:

gA;1-15;6;24.2
gA;3-17;8;31.7
gB;3-11;2;5.8
gB;1-13;1;3.9
gC;1-18;5;22.1
gC;2-19;3;9.5
gC;3-19;4;14.2
gB;2-11;3;12.2
gB;3-13;3;9.5

A doctest file is available at solargen_sum-test.txt.


The second function is

solargen_sum_ordered(fnamein, fnameout)

that does the same than solargen_sum(fnamein, fnameout) but the lines are ordered according to the following criteria:

  1. Alphabetically ordered by the group id.

  2. Decreasing order of the power produced.

For instance, the call solargen_sum('solargen_data.txt', 'solargen_sum_ordered_out.txt') should write the file solargen_sum_ordered_out.txt with the following info:

gA;3-17;8;31.7
gA;1-15;6;24.2
gB;2-11;3;12.2
gB;3-13;3;9.5
gB;3-11;2;5.8
gB;1-13;1;3.9
gC;1-18;5;22.1
gC;3-19;4;14.2
gC;2-19;3;9.5

A doctest file is available at solargen_sum_ordered-test.txt.