Changeset 14979 for trunk


Ignore:
Timestamp:
03/04/13 17:06:17 (12 years ago)
Author:
tbretz
Message:
Added the possibility to have colored lines in graphics; adaptes culmination and current prediction accordingly -- maybe colors still need adaption.
Location:
trunk/FACT++
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/smartfact.cc

    r14712 r14979  
    190190        };
    191191
    192         description = state[name];
     192        description = name[state];
    193193
    194194        const string arr = isday ?
     
    592592
    593593    template<class T>
    594         void WriteBinaryVec(const Time &tm, const string &fname, const vector<T> &vec, double scale, double offset=0, const string &title="")
     594        void WriteBinaryVec(const Time &tm, const string &fname, const vector<T> &vec, double scale, double offset=0, const string &title="", const string &col="")
    595595    {
    596596        if (vec.size()==0)
     
    611611            out << stat.max << '\x7f';
    612612        }
     613        if (!col.empty())
     614            out << col;
    613615        for (auto it=vec.begin(); it!=vec.end(); it++)
    614616        {
     
    633635        ofstream(fPath+"/"+fname+".bin") << out.str();
    634636    }
    635 
     637    /*
    636638    template<class T>
    637639        void WriteBinaryVec(const EventImp &d, const string &fname, const vector<T> &vec, double scale, double offset=0, const string &title="")
     
    650652    {
    651653        WriteBinaryVec(d.GetTime(), fname, vector<T>(&t, &t+1), scale, offset);
    652     }
     654    }*/
     655
     656    template<class T>
     657        void WriteHist(const EventImp &d, const string &fname, const T &t, double scale, double offset=0)
     658    {
     659        WriteBinaryVec(d.GetTime(), fname, vector<T>(&t, &t+1), scale, offset, "", "000");
     660    }
     661
     662    template<class T>
     663        void WriteCam(const EventImp &d, const string &fname, const T &t, double scale, double offset=0)
     664    {
     665        WriteBinaryVec(d.GetTime(), fname, vector<T>(&t, &t+1), scale, offset, "", "");
     666    }
     667
    653668
    654669    // -------------------------------------------------------------------
     
    741756#endif
    742757
    743         // [0] DimControl::kReady (Idle)
    744         // [1] DimControl::kLoad
    745         // [2] DimControl::kStarted
     758        // [0] DimControl::kIdle
     759        // [1] DimControl::kLoading
     760        // [2] DimControl::kCompiling
     761        // [3] DimControl::kRinning
    746762        if (d.GetQoS()==1)
    747763        {
     
    754770            HandleControlMessageImp(Event(d, file.data(), file.length()+1));
    755771
    756         // Not that this will also "ding" just after program startup
     772        // Note that this will also "ding" just after program startup
    757773        // if the dimctrl is still in state -3
    758774        if (d.GetQoS()==0)
     
    875891        ofstream(fPath+"/"+name+".data") << out.str();
    876892
    877         WriteBinary(d, "hist-magicweather-"+name, fMagicWeatherHist[i], max-min, min);
     893        WriteHist(d, "hist-magicweather-"+name, fMagicWeatherHist[i], max-min, min);
    878894    }
    879895
     
    938954        const double scale = stat.max>0 ? pow(10, ceil(log10(stat.max))) : 0;
    939955
    940         WriteBinary(d, "hist-tng-dust", fTngWeatherDustHist, scale);
     956        WriteHist(d, "hist-tng-dust", fTngWeatherDustHist, scale);
    941957
    942958        ostringstream out;
     
    10041020            fDriveControlTrackingDevHist.pop_front();
    10051021
    1006         WriteBinary(d, "hist-control-deviation", fDriveControlTrackingDevHist, 120);
     1022        WriteHist(d, "hist-control-deviation", fDriveControlTrackingDevHist, 120);
    10071023
    10081024        ostringstream out;
     
    10941110
    10951111        // Write the 160 patch values to a file
    1096         WriteBinary(d, "cam-feedback-deviation", dev, 1);
     1112        WriteCam(d, "cam-feedback-deviation", dev, 1);
    10971113
    10981114        const Statistics stat(dev, 3);
     
    11341150
    11351151        if (fDimBiasControl.state()==BIAS::State::kVoltageOn)
    1136             WriteBinary(d, "cam-biascontrol-voltage", val, 10, 65);
     1152            WriteCam(d, "cam-biascontrol-voltage", val, 10, 65);
    11371153        else
    1138             WriteBinary(d, "cam-biascontrol-voltage", val, 75);
     1154            WriteCam(d, "cam-biascontrol-voltage", val, 75);
    11391155
    11401156        ostringstream out;
     
    12101226
    12111227        // Write the 160 patch values to a file
    1212         WriteBinary(d, "cam-biascontrol-current", val, 100);
     1228        WriteCam(d, "cam-biascontrol-current", val, 100);
    12131229
    12141230        const Statistics stat(v, 0, 3);
     
    12241240
    12251241        // write the history to a file
    1226         WriteBinary(d, "hist-biascontrol-current", fBiasControlCurrentHist, 100);
     1242        WriteHist(d, "hist-biascontrol-current", fBiasControlCurrentHist, 100);
    12271243
    12281244        const string col0 = cal ? HTML::kGreen : HTML::kWhite;
     
    14141430        // FIXME: Add statistics for all kind of rates
    14151431
    1416         WriteBinary(d, "hist-ftmcontrol-triggerrate",
    1417                     fFtmControlTriggerRateHist, 100);
    1418         WriteBinary(d, "cam-ftmcontrol-boardrates",
    1419                     vector<float>(brates, brates+40), 10);
    1420         WriteBinary(d, "cam-ftmcontrol-patchrates",
    1421                     vector<float>(prates, prates+160), 10);
     1432        WriteHist(d, "hist-ftmcontrol-triggerrate",
     1433                  fFtmControlTriggerRateHist, 100);
     1434        WriteCam(d, "cam-ftmcontrol-boardrates",
     1435                 vector<float>(brates, brates+40), 10);
     1436        WriteCam(d, "cam-ftmcontrol-patchrates",
     1437                 vector<float>(prates, prates+160), 10);
    14221438
    14231439        ostringstream out;
     
    14621478        vector<uint16_t> vecb(dat.fMultiplicity, dat.fMultiplicity+40);
    14631479
    1464         WriteBinary(d, "cam-ftmcontrol-thresholds-patch", vecp, 1000);
    1465         WriteBinary(d, "cam-ftmcontrol-thresholds-board", vecb,  100);
     1480        WriteCam(d, "cam-ftmcontrol-thresholds-patch", vecp, 1000);
     1481        WriteCam(d, "cam-ftmcontrol-thresholds-board", vecb,  100);
    14661482
    14671483        const Statistics statp(vecp);
     
    15971613        switch (fFadControlDrsStep)
    15981614        {
    1599         case 0:  WriteBinary(d, "cam-fadcontrol-eventdata", max, 2,   -1); break;
    1600         case 1:  WriteBinary(d, "cam-fadcontrol-eventdata", max, 2,    0); break;
    1601         default: WriteBinary(d, "cam-fadcontrol-eventdata", max, 0.25, 0); break;
     1615        case 0:  WriteCam(d, "cam-fadcontrol-eventdata", max, 2,   -1); break;
     1616        case 1:  WriteCam(d, "cam-fadcontrol-eventdata", max, 2,    0); break;
     1617        default: WriteCam(d, "cam-fadcontrol-eventdata", max, 0.25, 0); break;
    16021618        }
    16031619
     
    16741690        ofstream(fPath+"/fsc.data") << out.str();
    16751691
    1676         WriteBinary(d, "hist-fsccontrol-temperature",
    1677                     fFscControlTemperatureHist, 10);
     1692        WriteHist(d, "hist-fsccontrol-temperature",
     1693                  fFscControlTemperatureHist, 10);
    16781694
    16791695        return GetCurrentState();
     
    17301746        fRateScanBoard %= 40;
    17311747
    1732         WriteBinary(d, "hist-ratescan",      fRateScanDataHist[0],                10, -2);
    1733         WriteBinary(d, "cam-ratescan-board", fRateScanDataHist[fRateScanBoard+1], 10, -4);
     1748        WriteHist(d, "hist-ratescan",      fRateScanDataHist[0],                10, -2);
     1749        WriteCam(d, "cam-ratescan-board", fRateScanDataHist[fRateScanBoard+1], 10, -4);
    17341750
    17351751        ostringstream out;
     
    17641780            fRateControlThreshold.pop_front();
    17651781
    1766         WriteBinary(d, "hist-ratecontrol-threshold", fRateControlThreshold, 1000);
     1782        WriteHist(d, "hist-ratecontrol-threshold", fRateControlThreshold, 1000);
    17671783
    17681784        return GetCurrentState();
     
    19972013                const double angle = m.Angle(src->ra, src->dec);
    19982014
    1999                 const double lc = angle*hrz.alt*pow(disk, 6)/360/360;
    2000 
    2001                 cur = 7.7+4942*lc;
     2015                // Current prediction
     2016                const double cang = sin(angle  *M_PI/180);
     2017                const double calt = sin(hrz.alt*M_PI/180);
     2018
     2019                const double lc = calt>0 ? cang*sqrt(calt)*pow(disk, 3) : -1;
     2020                cur = lc>0 ? 8+104.5*lc : -1;
    20022021
    20032022                vec.push_back(cur); // Covert LC to pixel current in uA
     
    20872106        out4 << now.JavaDate() << '\n';
    20882107
    2089         multimap<Time, pair<string, float>> culmination;
    2090         multimap<Time, pair<string, float>> lightcond;
     2108        struct Entry
     2109        {
     2110            string name;
     2111            float value;
     2112            int color;
     2113            Entry(const string &n, float v, int c) : name(n), value(v), color(c%8) { }
     2114
     2115            const string &Col() const
     2116            {
     2117                // If this list is updatd the number count in the constructor needs
     2118                // to be updated, too
     2119                static const string hcol[] = { "888", "8cf", "c8f", "bbb", "8fc", "cf8", "f8c", "fc8" };
     2120                return hcol[color];
     2121            }
     2122
     2123            vector<float> GetColor(double scale, double offset=0) const
     2124            {
     2125                vector<float> rc(3);
     2126                rc[0] = double(Col()[0])*scale/126+offset;
     2127                rc[1] = double(Col()[1])*scale/126+offset;
     2128                rc[2] = double(Col()[2])*scale/126+offset;
     2129                return rc;
     2130            }
     2131        };
     2132
     2133        multimap<Time, Entry> culmination;
     2134        multimap<Time, Entry> lightcond;
    20912135        vector<vector<float>> alt;
    20922136        vector<vector<float>> cur;
     
    20972141        observer.lat = lat;
    20982142
    2099         const pair<vector<float>, pair<Time, float>> vism = GetVisibility(0, &observer, now.JD());
     2143        int ccol = 0;
     2144        int lcol = 0;
     2145
     2146        /*const*/ pair<vector<float>, pair<Time, float>> vism = GetVisibility(0, &observer, now.JD());
    21002147        if (vism.first.size()>0)
    21012148        {
     2149            const Entry entry("Moon", vism.second.second, ccol);
     2150            culmination.insert(make_pair(vism.second.first, entry));
     2151            const vector<float> col = entry.GetColor(75, 15);
     2152            vism.first.insert(vism.first.begin(), col.begin(), col.end());
    21022153            alt.push_back(vism.first);
    2103             culmination.insert(make_pair(vism.second.first, make_pair("Moon", vism.second.second)));
     2154
     2155            ccol++;
    21042156        }
    21052157#endif
     
    21292181                ln_get_hrz_from_equ(&pos, &observer, now.JD(), &hrz);
    21302182
    2131                 const pair<vector<float>, pair<Time, float>> vis = GetVisibility(&pos, &observer, now.JD());
     2183                /*const*/ pair<vector<float>, pair<Time, float>> vis = GetVisibility(&pos, &observer, now.JD());
    21322184                if (vis.first.size()>0)
    21332185                {
     2186                    const Entry entry(name, vis.second.second, ccol);
     2187                    culmination.insert(make_pair(vis.second.first, entry));
     2188                    const vector<float> col = entry.GetColor(75, 15);
     2189                    vis.first.insert(vis.first.begin(), col.begin(), col.end());
    21342190                    alt.push_back(vis.first);
    2135                     culmination.insert(make_pair(vis.second.first, make_pair(name, vis.second.second)));
    2136 
    2137                     const pair<vector<float>, pair<Time, float>> lc = GetLightCondition(&pos, &observer, now.JD());
     2191
     2192                    ccol++;
     2193
     2194                    /*const*/ pair<vector<float>, pair<Time, float>> lc = GetLightCondition(&pos, &observer, now.JD());
    21382195                    if (lc.first.size()>0)
    21392196                    {
     2197                        const Entry entry2(name, lc.second.second, lcol);
     2198                        lightcond.insert(make_pair(lc.second.first, entry2));
     2199                        const vector<float> col2 = entry2.GetColor(100);
     2200                        lc.first.insert(lc.first.begin(), col2.begin(), col2.end());
    21402201                        cur.push_back(lc.first);
    2141                         lightcond.insert(make_pair(lc.second.first, make_pair(name, lc.second.second)));
     2202
     2203                        lcol++;
    21422204                    }
    21432205                }
     
    21722234            for (auto it=culmination.begin(); it!=culmination.end(); it++)
    21732235            {
     2236                const Entry &e = it->second;
    21742237                if (it!=culmination.begin())
    21752238                    out3 << ", ";
    2176                 out3 << "<B>" << it->second.first << "</B>";
    2177                 if (it->second.second>0)
    2178                     out3 << " [" << nearbyint(90-it->second.second) << "&deg;]";
     2239                out3 << "<B#" << e.Col() << ">" << e.name << "</B>";
     2240                if (e.value>0)
     2241                    out3 << " [" << nearbyint(90-e.value) << "&deg;]";
    21792242            }
    21802243
    21812244            out4 << setprecision(3);
     2245
    21822246            for (auto it=lightcond.begin(); it!=lightcond.end(); it++)
    21832247            {
     2248                const Entry &e = it->second;
    21842249                if (it!=lightcond.begin())
    21852250                    out4 << ", ";
    2186                 out4 << "<B>" << it->second.first << "</B>";
    2187                 if (it->second.second>0)
    2188                     out4 << " [" << nearbyint(it->second.second) << "]";
     2251                out4 << "<B#" << e.Col() << ">" << e.name << "</B>";
     2252                if (e.value>0)
     2253                    out4 << " [" << nearbyint(e.value) << "]";
    21892254            }
    21902255
  • trunk/FACT++/www/smartfact/index.js

    r14677 r14979  
    10911091            form = "&mdash;";
    10921092
     1093        form = form.replace(/<B#(.*?)>/g, "<b style='background:#$1'>");
    10931094        form = form.replace(/<#(.*?)>/g, "<font color='$1'>");
    10941095        form = form.replace(/<([\+-])>/g, "<font size='$11'>");
     
    14301431
    14311432    ctx.strokeStyle = "#666";
     1433    ctx.fillStyle = "#"+color(100);
    14321434
    14331435    // --- data ---
     
    14351437    for (var j=1; j<data.length; j++)
    14361438    {
    1437         if (data[j].length<2)
     1439        if (data[j].length<5)
    14381440            continue;
     1441
     1442        ctx.strokeStyle = "#"+data[j].substr(0, 3);
     1443        data[j] = data[j].substr(3);
    14391444
    14401445        ctx.beginPath();
     
    14461451        ctx.lineTo(cw-mr, ch-mb);
    14471452        ctx.lineTo(ml,    ch-mb);
    1448         ctx.fillStyle = "#"+color(100);
    14491453        ctx.stroke();
    14501454
Note: See TracChangeset for help on using the changeset viewer.