Search in sources :

Example 1 with MostActivatedAlarms

use of alma.alarmsystem.statistics.generated.MostActivatedAlarms in project ACS by ACS-Community.

the class StatHashMap method calculate.

/**
	 * Calculate the statistics of the passed time interval.
	 * <P>
	 * The figures calculated are:
	 * <UL>
	 * 	<LI>Total number of different alarms issued
	 * <LI>Total number of activations and terminations
	 * <LI>Total number of terminations
	 * 	<LI>Total number of activations
	 * 	<LI>Average number of activations and terminations per second
	 * 	<LI>The 5 alarms that has been changed (activated and/or terminated) more often
	 * 	<LI>The 5 alarms that has been activated more often
	 * 	<LI>The 5 alarms that has been terminated more often
	 * </UL>
	 * 
	 * @param statStruct The object with numbers for the statistics
	 * @throws IOException In case of error with the file
	 * @throws ValidationException In case of error validating data
	 * @throws MarshalException IN case of error "marshalling" data on file
	 */
private void calculate(StatStruct statStruct) throws IOException, MarshalException, ValidationException {
    // A collection to iterate over the values
    List<AlarmInfo> infos = new ArrayList<AlarmInfo>(statStruct.alarmsInfo.values());
    // The number of different alarms published in the interval
    int totAlarms = infos.size();
    // Total number of operations (i.e. activations and terminations)
    int totOperations = statStruct.numActiavations + statStruct.numTerminations;
    // Average number of operations per second
    float avgOpPerSecond = (float) totOperations / (float) (timeInterval * 60);
    // Get the file to write the statistics
    BufferedWriter outF;
    try {
        outF = openOutputFile();
    } catch (Throwable t) {
        logger.log(AcsLogLevel.ERROR, "Can't write on file: statistics lost", t);
        return;
    }
    // Build the string to write on disk (help of castor)
    Record statRec = new Record();
    statRec.setTimestamp(IsoDateFormat.formatCurrentDate());
    statRec.setProcessedAlarmTypes(totAlarms);
    statRec.setActivations(statStruct.numActiavations);
    statRec.setTerminations(statStruct.numTerminations);
    statRec.setTotalAlarms(totOperations);
    statRec.setAvgAlarmsPerSecond(Float.valueOf(String.format("%.2f", avgOpPerSecond)));
    MostActivatedAlarms maa = new MostActivatedAlarms();
    Collections.sort(infos, new ComparatorByType(AlarmInfo.VALUE_TYPE.ACTIVATIONS));
    maa.setID(appendListOfAlarms(infos, AlarmInfo.VALUE_TYPE.ACTIVATIONS, 4));
    statRec.setMostActivatedAlarms(maa);
    MostTerminatedAlarms mta = new MostTerminatedAlarms();
    Collections.sort(infos, new ComparatorByType(AlarmInfo.VALUE_TYPE.TERMINATIONS));
    mta.setID(appendListOfAlarms(infos, AlarmInfo.VALUE_TYPE.TERMINATIONS, 4));
    statRec.setMostTerminatedAlarms(mta);
    MostActivatedTerminatedAlarms mata = new MostActivatedTerminatedAlarms();
    Collections.sort(infos, new ComparatorByType(AlarmInfo.VALUE_TYPE.OPERATIONS));
    mata.setID(appendListOfAlarms(infos, AlarmInfo.VALUE_TYPE.OPERATIONS, 4));
    statRec.setMostActivatedTerminatedAlarms(mata);
    Marshaller marshaller = getMarshaller(outF);
    marshaller.marshal(statRec);
    // This string appears at the end of the XML file
    outF.write(closeXMLTag);
    statStruct.alarmsInfo.clear();
    infos.clear();
    outF.flush();
    outF.close();
}
Also used : MostActivatedTerminatedAlarms(alma.alarmsystem.statistics.generated.MostActivatedTerminatedAlarms) Marshaller(org.exolab.castor.xml.Marshaller) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) Record(alma.alarmsystem.statistics.generated.Record) MostTerminatedAlarms(alma.alarmsystem.statistics.generated.MostTerminatedAlarms) MostActivatedAlarms(alma.alarmsystem.statistics.generated.MostActivatedAlarms)

Aggregations

MostActivatedAlarms (alma.alarmsystem.statistics.generated.MostActivatedAlarms)1 MostActivatedTerminatedAlarms (alma.alarmsystem.statistics.generated.MostActivatedTerminatedAlarms)1 MostTerminatedAlarms (alma.alarmsystem.statistics.generated.MostTerminatedAlarms)1 Record (alma.alarmsystem.statistics.generated.Record)1 BufferedWriter (java.io.BufferedWriter)1 ArrayList (java.util.ArrayList)1 Marshaller (org.exolab.castor.xml.Marshaller)1