package org.bench4q.web.service;

import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.bench4q.share.helper.ExceptionLog;
import org.bench4q.share.models.master.statistics.SampleModel;
import org.bench4q.web.model.ResultModel;
import org.springframework.stereotype.Component;

@Component
public class MonitorService {

	private Logger logger = Logger.getLogger(MonitorService.class);

	public List<ResultModel> extractMonitorResult(
			List<? extends SampleModel> list, String fieldName) {
		if (list == null)
			return null;
		List<ResultModel> resultModels = new ArrayList<ResultModel>();
		List<String> fieldNames = new ArrayList<String>();
		fieldNames.add(fieldName);
		for (SampleModel sampleModel : list) {
			if (sampleModel != null) {
				ResultModel resultModel;
				try {
					resultModel = ChangeToResultModel.getResultModel(
							sampleModel, fieldNames);
					resultModel.setTime(sampleModel.getSamplingTime());
					resultModel.setFinished(sampleModel.isFinished());
					resultModels.add(resultModel);
				} catch (NoSuchFieldException e) {
					// TODO Auto-generated catch block
					logger.info(ExceptionLog.getStackTrace(e));
				}

			}
		}
		return resultModels;
	}

}
