def do_processing(scalars, pathname_maps, tw_values):
    # open files 1 and file 2 and loop over to plot
    dss_group1 = vutils.opendss(scalars['FILE1'])
    dss_group2 = vutils.opendss(scalars['FILE2'])
    time_windows = map(lambda val: val[1].replace('"',''), tw_values)
    tws = map(lambda x: vtimeseries.timewindow(x), time_windows)
    if len(tws) > 0:
        tw=tws[0]
    else:
        tw=None
    output_file=scalars['OUTFILE']
    data_output_file = output_file.split(".")[0]+".js"
    fh=open(data_output_file,'w')
    print >> fh, """/*
    Comparison Output File
    Generated on : %s
    */"""%(str(Date()))
    js_data.write_begin_data_array(fh);
    if dss_group1 == None or dss_group2 == None:
        sys.exit(2);
    dataIndex=0
    for path_map in pathname_maps:
        dataIndex=dataIndex+1
        logging.debug('Working on index: %d'%dataIndex)
        if dataIndex>1:
            fh.write(",")
        #path_map = pathname_mapping[var_name]
        if path_map.path2==None or path_map.path2 == "":
            path_map.path2=path_map.path1
        var_name = path_map.var_name
        calculate_dts=0
        if path_map.var_category == 'HEADER':
            logging.debug('Inserting header')
            continue;
        if path_map.report_type == 'Exceedance_Post':
            calculate_dts=1
        ref1 = get_ref(dss_group1, path_map.path1,calculate_dts, pathname_maps, 1)
        ref2 = get_ref(dss_group2, path_map.path2,calculate_dts, pathname_maps, 2)
        if (ref1==None or ref2==None): 
            continue
        series_name = [scalars['NAME1'],scalars['NAME2']]
        data_units=get_units(ref1,ref2)
        data_type=get_type(ref1,ref2)
        if path_map.report_type == 'Average':
            write_plot_data(fh, build_data_array(ref1,ref2,tw), dataIndex, "Average %s"%path_map.var_name.replace('"',''), series_name, "%s(%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES)
        elif path_map.report_type == 'Exceedance':
            write_plot_data(fh, build_exceedance_array(ref1,ref2,path_map.var_category=='S_SEPT',tw), dataIndex, get_exceedance_plot_title(path_map), series_name, "%s(%s)"%(data_type,data_units), "Percent at or above", PlotType.EXCEEDANCE)
        elif path_map.report_type == 'Avg_Excd':
            write_plot_data(fh, build_data_array(ref1,ref2,tw), dataIndex, "Average %s"%path_map.var_name.replace('"',''), series_name, "%s(%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES)
            fh.write(",")
            write_plot_data(fh, build_exceedance_array(ref1,ref2,path_map.var_category=='S_SEPT',tw), dataIndex, get_exceedance_plot_title(path_map), series_name, "%s(%s)"%(data_type,data_units), "Percent at or above", PlotType.EXCEEDANCE)
        elif path_map.report_type == 'Timeseries':
            write_plot_data(fh, build_data_array(ref1,ref2,tw), dataIndex, "Average %s"%path_map.var_name.replace('"',''), series_name, "%s(%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES)
        elif path_map.report_type == 'Exceedance_Post':
            write_plot_data(fh, build_exceedance_array(ref1,ref2,tw), dataIndex, "Exceedance %s"%path_map.var_name.replace('"',''), series_name, "%s(%s)"%(data_type,data_units), "Percent at or above", PlotType.EXCEEDANCE)
    js_data.write_end_data_array(fh);
    logging.debug('Writing end of data array')
    fh.close()
    # Generate the main html file
    fh=open(scalars['OUTFILE'],'w')
    print >> fh, """ 
<html>
<head>
<title>Calsim Report: %s vs %s</title>
<script type="text/javascript" src="%s"></script>
<script type="text/javascript" src="report-common/protovis-d3.3.js"></script>
<script type="text/javascript" src="report-common/plots.js"></script>
<script type="text/javascript" src="report-common/jquery-1.4.2.min.js"></script> 
<link rel="stylesheet" type="text/css" media="print" href="report-common/print.css" /> 
<link rel="stylesheet" type="text/css" media="screen" href="report-common/screen.css" /> 
</head>
"""%(scalars['NAME1'],scalars['NAME2'],data_output_file)
    write_control_panel(fh,scalars, pathname_maps,tw_values)
    write_water_balance_table(fh,dss_group1, dss_group2, scalars, pathname_maps,tw_values)
    print >> fh, """<script type="text/javascript"> 
    function clear_and_draw(sdate, edate){
        $('.plot').empty();
        n=data.length
        plot_diff = $('input[name=diff_plot]').is(':checked') ? 1 : 0 ;
        for(i=0; i < n; i++){
            var div_id = "fig"+(i+1);
            if (data[i]==null) continue;
            if ($("#"+div_id).length==0){
                $("body").append('<a href="#'+div_id+'"><div class="plot" id="'+div_id+'"></div></a>');
            }
            if (data[i].plot_type=="timeseries"){
                plots.time_series_plot(div_id,data[i],plot_diff,sdate,edate);
            }else if (data[i].plot_type=="exceedance"){
                plots.exceedance_plot(div_id,data[i],null,sdate,edate);
            }
        }
        // update links
    };
    $(document).ready(clear_and_draw(null,null));
    $('#system-water-balance-table tr').click(function(){
        var_name = $($(this).find('td')[0]).text();
        var svg_element = $('div').filter(function(){ return $(this).text().indexOf(var_name)>=0;})
        if (svg_element && svg_element.length > 0){
            anchor_name = $($(svg_element[0]).parent()).attr("href");
            window.location.href=window.location.href.split('#')[0]+anchor_name;
        }
    });
</script> 
<script type="text/javascript"> 
    function extract_date(date_str){
        date_fields=date_str.split(",");
        return new Date(date_fields[0],date_fields[1],date_fields[2]);
    }
    $('#time-window-select').change(function(){
        var changed_val = $('#time-window-select option:selected').val().split("-");
        clear_and_draw(extract_date(changed_val[0]),extract_date(changed_val[1]));
    });
    $('#threshold').change(function(){
        set_diff_threshold($('#threshold').val());
    });
    $('input[name=diff_plot]').change(function(){
        var changed_val = $('#time-window-select option:selected').val().split("-");
        clear_and_draw(extract_date(changed_val[0]),extract_date(changed_val[1]));
    });

    function set_diff_threshold(threshold){
      var diff_marker = function(){
        if(Math.abs(parseFloat($(this).text())) >= threshold){
           $(this).addClass('large-diff');
        }else{
           $(this).removeClass('large-diff');
        };
      };
      $('tr td:nth-child(5)').each(diff_marker);
      $('tr td:nth-child(9)').each(diff_marker);
      $('tr td:nth-child(13)').each(diff_marker);
    };
    set_diff_threshold($('#threshold').val());
</script> 
 
</body> 
 
</html>"""
    fh.close()    
    logging.debug('Closed out data file')
Exemple #2
0
def do_processing(scalars, pathname_maps, tw_values):
    # open files 1 and file 2 and loop over to plot
    dss_group1 = vutils.opendss(scalars['FILE1'])
    dss_group2 = vutils.opendss(scalars['FILE2'])
    time_windows = map(lambda val: val[1].replace('"',''), tw_values)
    tws = map(lambda x: vtimeseries.timewindow(x), time_windows)
    if len(tws) > 0:
        tw=tws[0]
    else:
        tw=None
    output_file=scalars['OUTFILE']
    data_output_file = output_file.split(".")[0]+".js"
    fh=open(data_output_file,'w')
    print >> fh, """/*
    Comparison Output File
    Generated on : %s
    */"""%(str(Date()))
    js_data.write_begin_data_array(fh);
    if dss_group1 == None or dss_group2 == None:
        sys.exit(2);
    dataIndex=0
    for path_map in pathname_maps:
        dataIndex=dataIndex+1
        logging.debug('Working on index: %d'%dataIndex)
        if dataIndex>1:
            fh.write(",")
        #path_map = pathname_mapping[var_name]
        if path_map.path2==None or path_map.path2 == "":
            path_map.path2=path_map.path1
        var_name = path_map.var_name
        calculate_dts=0
        if path_map.var_category == 'HEADER':
            logging.debug('Inserting header')
            continue;
        if path_map.report_type == 'Exceedance_Post':
            calculate_dts=1
        ref1 = get_ref(dss_group1, path_map.path1,calculate_dts, pathname_maps, 1)
        ref2 = get_ref(dss_group2, path_map.path2,calculate_dts, pathname_maps, 2)
        if (ref1==None or ref2==None): 
            continue
        series_name = [scalars['NAME1'],scalars['NAME2']]
        data_units=get_units(ref1,ref2)
        data_type=get_type(ref1,ref2)
        if path_map.report_type == 'Average':
            write_plot_data(fh, build_data_array(ref1,ref2,tw), dataIndex, "Average %s"%path_map.var_name.replace('"',''), series_name, "%s(%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES)
        elif path_map.report_type == 'Exceedance':
            write_plot_data(fh, build_exceedance_array(ref1,ref2,path_map.var_category=='S_SEPT',tw), dataIndex, get_exceedance_plot_title(path_map), series_name, "%s(%s)"%(data_type,data_units), "Percent at or above", PlotType.EXCEEDANCE)
        elif path_map.report_type == 'Avg_Excd':
            write_plot_data(fh, build_data_array(ref1,ref2,tw), dataIndex, "Average %s"%path_map.var_name.replace('"',''), series_name, "%s(%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES)
            fh.write(",")
            write_plot_data(fh, build_exceedance_array(ref1,ref2,path_map.var_category=='S_SEPT',tw), dataIndex, get_exceedance_plot_title(path_map), series_name, "%s(%s)"%(data_type,data_units), "Percent at or above", PlotType.EXCEEDANCE)
        elif path_map.report_type == 'Timeseries':
            write_plot_data(fh, build_data_array(ref1,ref2,tw), dataIndex, "Average %s"%path_map.var_name.replace('"',''), series_name, "%s(%s)"%(data_type,data_units), "Time", PlotType.TIME_SERIES)
        elif path_map.report_type == 'Exceedance_Post':
            write_plot_data(fh, build_exceedance_array(ref1,ref2,tw), dataIndex, "Exceedance %s"%path_map.var_name.replace('"',''), series_name, "%s(%s)"%(data_type,data_units), "Percent at or above", PlotType.EXCEEDANCE)
    js_data.write_end_data_array(fh);
    logging.debug('Writing end of data array')
    fh.close()
    # Generate the main html file
    fh=open(scalars['OUTFILE'],'w')
    print >> fh, """ 
<html>
<head>
<title>Calsim Report: %s vs %s</title>
<script type="text/javascript" src="%s"></script>
<script type="text/javascript" src="report-common/protovis-d3.3.js"></script>
<script type="text/javascript" src="report-common/plots.js"></script>
<script type="text/javascript" src="report-common/jquery-1.4.2.min.js"></script> 
<link rel="stylesheet" type="text/css" media="print" href="report-common/print.css" /> 
<link rel="stylesheet" type="text/css" media="screen" href="report-common/screen.css" /> 
</head>
"""%(scalars['NAME1'],scalars['NAME2'],data_output_file)
    write_control_panel(fh,scalars, pathname_maps,tw_values)
    write_water_balance_table(fh,dss_group1, dss_group2, scalars, pathname_maps,tw_values)
    print >> fh, """<script type="text/javascript"> 
    function clear_and_draw(sdate, edate){
        $('.plot').empty();
        n=data.length
        plot_diff = $('input[name=diff_plot]').is(':checked') ? 1 : 0 ;
        for(i=0; i < n; i++){
            var div_id = "fig"+(i+1);
            if (data[i]==null) continue;
            if ($("#"+div_id).length==0){
                $("body").append('<a href="#'+div_id+'"><div class="plot" id="'+div_id+'"></div></a>');
            }
            if (data[i].plot_type=="timeseries"){
                plots.time_series_plot(div_id,data[i],plot_diff,sdate,edate);
            }else if (data[i].plot_type=="exceedance"){
                plots.exceedance_plot(div_id,data[i],null,sdate,edate);
            }
        }
        // update links
    };
    $(document).ready(clear_and_draw(null,null));
    $('#system-water-balance-table tr').click(function(){
        var_name = $($(this).find('td')[0]).text();
        var svg_element = $('div').filter(function(){ return $(this).text().indexOf(var_name)>=0;})
        if (svg_element && svg_element.length > 0){
            anchor_name = $($(svg_element[0]).parent()).attr("href");
            window.location.href=window.location.href.split('#')[0]+anchor_name;
        }
    });
</script> 
<script type="text/javascript"> 
    function extract_date(date_str){
        date_fields=date_str.split(",");
        return new Date(date_fields[0],date_fields[1],date_fields[2]);
    }
    $('#time-window-select').change(function(){
        var changed_val = $('#time-window-select option:selected').val().split("-");
        clear_and_draw(extract_date(changed_val[0]),extract_date(changed_val[1]));
    });
    $('#threshold').change(function(){
        set_diff_threshold($('#threshold').val());
    });
    $('input[name=diff_plot]').change(function(){
        var changed_val = $('#time-window-select option:selected').val().split("-");
        clear_and_draw(extract_date(changed_val[0]),extract_date(changed_val[1]));
    });

    function set_diff_threshold(threshold){
      var diff_marker = function(){
        if(Math.abs(parseFloat($(this).text())) >= threshold){
           $(this).addClass('large-diff');
        }else{
           $(this).removeClass('large-diff');
        };
      };
      $('tr td:nth-child(5)').each(diff_marker);
      $('tr td:nth-child(9)').each(diff_marker);
      $('tr td:nth-child(13)').each(diff_marker);
    };
    set_diff_threshold($('#threshold').val());
</script> 
 
</body> 
 
</html>"""
    fh.close()    
    logging.debug('Closed out data file')
                        latlng=['nan','nan','nan','nan']
                        print "can't find the Lat/Lng for ",p.getPart(p.B_PART)
                    if dIndex>1: 
                        fl.write(",")
                
                    if  name in output_values:      
                        write_list_data(fl,name, str_refvar, p.getPart(p.B_PART), cpart, 1, diff_arr,latlng)
                    else:
                        write_list_data(fl,name, str_refvar, p.getPart(p.B_PART), cpart, 0, diff_arr,latlng)              
            else:
                logging.debug("*** Please verify the path for "+name+" ***")               

                
    logging.debug('Writing end of data array')
    for i in type_arr:
        js_data.write_end_data_array(fs_davg[i])
        js_data.write_end_data_array(fs_dmax[i])
        js_data.write_end_data_array(fs_dmin[i])
        js_data.write_end_data_array(fs_mavg[i])
        fs_davg[i].close()
        fs_dmax[i].close()
        fs_dmin[i].close()
        fs_mavg[i].close()
        if globals['PLOT_ORIGINAL_TIME_INTERVAL']=='ON':
            js_data.write_end_data_array(fs_orig[i])
            fs_orig[i].close()
    js_data_list.write_end_data_array(fl)
    fl.close()
    # Generate the main html file
    fh = open(output_dir+scalars['OUTFILE'],'w')
    print >> fh, """ 
Exemple #4
0
                    if name in output_values:
                        write_list_data(fl, name, str_refvar,
                                        p.getPart(p.B_PART), cpart, 1,
                                        diff_arr, latlng)
                    else:
                        write_list_data(fl, name, str_refvar,
                                        p.getPart(p.B_PART), cpart, 0,
                                        diff_arr, latlng)
            else:
                logging.debug("*** Please verify the path for " + name +
                              " ***")

    logging.debug('Writing end of data array')
    for i in type_arr:
        js_data.write_end_data_array(fs_davg[i])
        js_data.write_end_data_array(fs_dmax[i])
        js_data.write_end_data_array(fs_dmin[i])
        js_data.write_end_data_array(fs_mavg[i])
        fs_davg[i].close()
        fs_dmax[i].close()
        fs_dmin[i].close()
        fs_mavg[i].close()
        if globals['PLOT_ORIGINAL_TIME_INTERVAL'] == 'ON':
            js_data.write_end_data_array(fs_orig[i])
            fs_orig[i].close()
    js_data_list.write_end_data_array(fl)
    fl.close()
    # Generate the main html file
    fh = open(output_dir + scalars['OUTFILE'], 'w')
    print >> fh, """