blob: 17ede362d9576da49aaf29ab9faa8f9cf3606020 [file] [log] [blame]
// ExternalDataSourceDiseaseModelImpl
package org.eclipse.stem.diseasemodels.externaldatasource.impl;
/*******************************************************************************
* Copyright (c) 2007, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.ui.provider.PropertySource;
import org.eclipse.osgi.util.NLS;
import org.eclipse.stem.analysis.LogInitializationException;
import org.eclipse.stem.analysis.util.CSVScenarioStreamer;
import org.eclipse.stem.analysis.util.CSVscenarioLoader;
import org.eclipse.stem.core.Utility;
import org.eclipse.stem.core.common.Identifiable;
import org.eclipse.stem.core.common.StringValue;
import org.eclipse.stem.core.graph.DynamicLabel;
import org.eclipse.stem.core.graph.Graph;
import org.eclipse.stem.core.graph.LabelValue;
import org.eclipse.stem.core.graph.NodeLabel;
import org.eclipse.stem.core.model.Decorator;
import org.eclipse.stem.core.model.STEMTime;
import org.eclipse.stem.core.scenario.ScenarioInitializationException;
import org.eclipse.stem.definitions.adapters.relativevalue.RelativeValueProvider;
import org.eclipse.stem.definitions.adapters.relativevalue.RelativeValueProviderAdapter;
import org.eclipse.stem.definitions.adapters.relativevalue.RelativeValueProviderAdapterFactory;
import org.eclipse.stem.definitions.labels.AreaLabel;
import org.eclipse.stem.definitions.labels.PopulationLabel;
import org.eclipse.stem.diseasemodels.Activator;
import org.eclipse.stem.diseasemodels.externaldatasource.ExternalDataSourceDiseaseModel;
import org.eclipse.stem.diseasemodels.externaldatasource.ExternalDataSourcePackage;
import org.eclipse.stem.diseasemodels.standard.impl.StandardDiseaseModelImpl;
import org.eclipse.stem.diseasemodels.standard.DiseaseModel;
import org.eclipse.stem.diseasemodels.standard.DiseaseModelLabel;
import org.eclipse.stem.diseasemodels.standard.DiseaseModelLabelValue;
import org.eclipse.stem.diseasemodels.standard.Infector;
import org.eclipse.stem.diseasemodels.standard.SEIRLabelValue;
import org.eclipse.stem.diseasemodels.standard.SILabelValue;
import org.eclipse.stem.diseasemodels.standard.SIRLabelValue;
import org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabel;
import org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabelValue;
import org.eclipse.stem.diseasemodels.standard.StandardFactory;
import org.eclipse.stem.diseasemodels.standard.StandardPackage;
import org.eclipse.stem.diseasemodels.standard.impl.SEIRLabelValueImpl;
import org.eclipse.stem.diseasemodels.standard.impl.SILabelValueImpl;
import org.eclipse.stem.diseasemodels.standard.impl.SIRLabelValueImpl;
import org.eclipse.stem.diseasemodels.standard.provider.StandardItemProviderAdapterFactory;
import org.eclipse.stem.populationmodels.standard.PopulationModelLabel;
import org.eclipse.stem.populationmodels.standard.StandardPopulationModelLabel;
import org.eclipse.stem.populationmodels.standard.StandardPopulationModelLabelValue;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Disease Model</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.stem.diseasemodels.externaldatasource.impl.ExternalDataSourceDiseaseModelImpl#getDataPath <em>Data Path</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.externaldatasource.impl.ExternalDataSourceDiseaseModelImpl#getDiseaseType <em>Disease Type</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class ExternalDataSourceDiseaseModelImpl extends StandardDiseaseModelImpl implements ExternalDataSourceDiseaseModel {
/**
* The default value of the '{@link #getDataPath() <em>Data Path</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getDataPath()
* @generated
* @ordered
*/
protected static final String DATA_PATH_EDEFAULT = null;
/**
* The cached value of the '{@link #getDataPath() <em>Data Path</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getDataPath()
* @generated
* @ordered
*/
protected String dataPath = DATA_PATH_EDEFAULT;
//private final static String URI_PREFIX_PATTERN = "geo/region/";
/**
* The default value of the '{@link #getDiseaseType() <em>Disease Type</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getDiseaseType()
* @generated
* @ordered
*/
protected static final String DISEASE_TYPE_EDEFAULT = null;
/**
* This prefix precedes the node id and must be removed in the
* filterFilename method to auto-generate the output file name.
*/
public static final String LOCATIONID_PREFIX = "/node/geo/region/";
/**
* Directory containing the scenario to import and play back
*/
public String dirName = DEFAULT_DIR;
/**
* a false (Hidden) time counter used for this toy example
*/
private int fileLineCounter = 0;
// These are only used when we do not know which disease model
// generated the logged data. We can handle only S, E, I and R
// compartments in such cases.
protected Set<String> S_KEY_SET = new HashSet<String>();
protected Set<String> E_KEY_SET = new HashSet<String>();
protected Set<String> I_KEY_SET = new HashSet<String>();
protected Set<String> R_KEY_SET = new HashSet<String>();
protected Set<String> INCIDENCE_KEY_SET = new HashSet<String>();
public static String labelS = null ;
public static String labelE = null ;
public static String labelI = null ;
public static String labelR = null ;
public static String labelIncidence = null;
// When we know the disease model that generated the data (stored in the runparameters file),
// the descriptors of the properties are stored here, mapped by the population id
protected Map<String, List<IItemPropertyDescriptor>> propertyDescriptors;
// We need this to determine when a simulation is restarted so we
// can reset the file line counter. Also needed to keep track of the line number in the file
private STEMTime firstSTEMTime = null;
// The streamer
CSVScenarioStreamer streamer;
/**
* not used
*/
private double totalPopulationCount = 0.0;
private double totalArea = 0.0;
private String diseaseType;
private Decorator diseaseModel;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public ExternalDataSourceDiseaseModelImpl() {
super();
}
/**
* We need to override this method to return all population model labels found in the logged files
*
* @param populationIdentifier
* the population being labeled. Only used if we do not know the name of the population.
* @param graph
* the graph to search
* @return the PopulationLabel instances of the graph that match the
* identifier.
*/
@Override
public EList<PopulationModelLabel> getPopulationModelLabels(
String populationIdentifier, Graph graph) throws ScenarioInitializationException {
final EList<PopulationModelLabel> retValue = new BasicEList<PopulationModelLabel>();
// If already done nothing will happen here
setupStreaming();
// Iterate through all of the population labels in the graph
EList<NodeLabel> labels = graph.getNodeLabelsByTypeURI(
PopulationModelLabel.URI_TYPE_DYNAMIC_POPULATION_LABEL);
boolean found = false;
for (NodeLabel pl:labels) {
final PopulationModelLabel populationLabel = (PopulationModelLabel) pl;
// Is this label for the population we're looking for?
boolean keep = false;
if(this.streamer.getDecorator() != null) {
// We have read the runparameters file and hence we know the names of the
// populations we're looking for
for(String loggedPopulation:this.streamer.getPopulationIdentifiers())
if(populationLabel.getPopulationIdentifier().equals(loggedPopulation)) keep = true;
} else {
// We do not know the population, use the popultion specified in this model
if(populationLabel.getPopulationIdentifier().equals(populationIdentifier)) keep = true;
}
if (keep) {
// Yes
// If there is a problem with the "node uri" of the population
// label then it would not have been associated with a node
// instance in the graph at this point. This is a problem for
// disease models that are trying to label the node (there isn't
// one!). So filter out those mistakes here.
// Does the population label have an associated node?
if (populationLabel.getNode() != null) {
// Yes
retValue.add(populationLabel);
} // if the population label has a node
} // if the population we're looking for
} // for each population label
return retValue;
}
/**
* Need to override this to set the initial value to the first row in the log file
* @generated NOT
*/
public void resetLabels() throws ScenarioInitializationException {
setEnabled(ENABLED_EDEFAULT);
setGraphDecorated(GRAPH_DECORATED_EDEFAULT);
try {
if(streamer != null)
streamer.close();
} catch(IOException ioe) {
throw new ScenarioInitializationException("IOException closing streamer", this, ioe);
}
streamer = null;
setupStreaming();
for (final Iterator<DynamicLabel> labelIter = getLabelsToUpdate()
.iterator(); labelIter.hasNext();) {
final StandardDiseaseModelLabel diseaseLabel = (StandardDiseaseModelLabel)labelIter.next();
// This is the current state of the disease for this label
final StandardDiseaseModelLabelValue deltaState = (StandardDiseaseModelLabelValue)diseaseLabel.getDeltaValue();
importDiseaseData(deltaState, diseaseLabel, null, 0); // last params not used
((StandardDiseaseModelLabelValue)((StandardDiseaseModelLabel)diseaseLabel).getCurrentValue()).add(deltaState);
}
} // resetLabels
/**
* get the constants which identify the disease label state variables
* @param diseaseLabel
*/
private void setPropertyLabels() {
StandardItemProviderAdapterFactory itemProviderFactory = new StandardItemProviderAdapterFactory();
if(diseaseModel == null) {
// We do not know the disease model and hence the label values needed
SEIRLabelValue diseaseLabel = (SEIRLabelValue) StandardFactory.eINSTANCE.createSEIRLabel().getCurrentValue();
IItemPropertySource propertySource = (IItemPropertySource) itemProviderFactory.adapt(diseaseLabel, PropertySource.class);
List<IItemPropertyDescriptor> properties = propertySource.getPropertyDescriptors(null);
IItemPropertyDescriptor propertyS = properties.get(StandardPackage.SEIR_LABEL_VALUE__S);
IItemPropertyDescriptor propertyE = properties.get(StandardPackage.SEIR_LABEL_VALUE__E);
IItemPropertyDescriptor propertyI = properties.get(StandardPackage.SEIR_LABEL_VALUE__I);
IItemPropertyDescriptor propertyR = properties.get(StandardPackage.SEIR_LABEL_VALUE__R);
IItemPropertyDescriptor propertyIncidence = properties.get(StandardPackage.SEIR_LABEL_VALUE__INCIDENCE);
labelS = propertyS.getDisplayName(propertyS);
labelE = propertyE.getDisplayName(propertyE);
labelI = propertyI.getDisplayName(propertyI);
labelR = propertyR.getDisplayName(propertyR);
labelIncidence = propertyIncidence.getDisplayName(propertyIncidence);
} else {
DiseaseModel dm = (DiseaseModel)diseaseModel;
for(String popId:streamer.getPopulationIdentifiers()) {
DiseaseModelLabel dml = dm.createDiseaseModelLabel(popId);
final RelativeValueProviderAdapter rvp = (RelativeValueProviderAdapter) RelativeValueProviderAdapterFactory.INSTANCE
.adapt(dml, RelativeValueProvider.class);
rvp.setTarget(dml);
List<IItemPropertyDescriptor> properties = rvp.getProperties();
// IItemPropertySource propertySource = (IItemPropertySource) itemProviderFactory.adapt(dmlv, PropertySource.class);
// List<IItemPropertyDescriptor> properties = propertySource.getPropertyDescriptors(null);
if(propertyDescriptors == null) propertyDescriptors = new HashMap<String, List<IItemPropertyDescriptor>>();
propertyDescriptors.put(popId, properties);
}
}
}// setPropertyLabels
/**
*
*/
private synchronized void setupStreaming() {
if(streamer == null) {
try {
streamer = new CSVScenarioStreamer(this.dataPath);
this.diseaseModel = streamer.getDecorator();
if(this.diseaseModel == null) {
streamer.prepareForStreaming(CSVscenarioLoader.UNKNOWN_POP_IDENTIFIER_KEY, -1);
// Set the disease type here since we don't need that
// input from the end-user any longer
this.diseaseType = streamer.getType(CSVscenarioLoader.UNKNOWN_POP_IDENTIFIER_KEY).name();
this.S_KEY_SET = streamer.getsKeySet();
this.E_KEY_SET = streamer.geteKeySet();
this.I_KEY_SET = streamer.getiKeySet();
this.R_KEY_SET = streamer.getrKeySet();
this.INCIDENCE_KEY_SET = streamer.getIncidenceKeySet();
} else {
for(String pop:streamer.getPopulationIdentifiers())
streamer.prepareForStreaming(pop, -1);
}
} catch(LogInitializationException sie) {
Activator.logError("Error reading scenario files", sie);
} catch(IOException ioe) {
Activator.logError("IOExceptopn reading scenario files", ioe);
}
}
}
/**
*
* This method reads the next state data from the external dataFile
*
* @param deltaState
* @param diseaseLabel
* @param time
* @param timeDelta
* @param streamNextRow True if we should fetch the next row from stream
* @return
*/
@SuppressWarnings("boxing")
public StandardDiseaseModelLabelValue importDiseaseData(
final StandardDiseaseModelLabelValue deltaState,
final StandardDiseaseModelLabel diseaseLabel,
final STEMTime time,
final long timeDelta) {
try {
// Will only be set up first time called
setupStreaming();
if(labelS==null && propertyDescriptors == null)
setPropertyLabels();
// TODO
// the filename actually comes from the node itself
// we need to regen the code with a scenarioDirectory
// specification as every node maps to a different data file. for now we will test
// with only one node and one file
// need a map of maps keyed by location name
Identifiable ident = diseaseLabel.getIdentifiable();
String fileName = ident.getURI().toString();
int last = fileName.lastIndexOf(LOCATIONID_PREFIX);
last += LOCATIONID_PREFIX.length();
String location = fileName.substring(last,fileName.length());
int adminLevel = Utility.keyLevel(location);
String population = diseaseLabel.getPopulationModelLabel().getPopulationIdentifier();
// if no data
/* if((data==null)||(data.size() == 0)) {
// no data for location in questions
if (diseaseType.equals(IMPORT_TYPE_SI)) {
return new SILabelValueImpl(0.0 , 0.0, 0.0, 0.0);
} else if (diseaseType.equals(IMPORT_TYPE_SIR)) {
return new SIRLabelValueImpl(0.0, 0.0 , 0.0, 0.0, 0.0);
} else if (diseaseType.equals(IMPORT_TYPE_SEIR)) {
return new SEIRLabelValueImpl( 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0);
} else {
throw new UnsupportedOperationException("ExternalDataSource Invalid Type "+diseaseType+" must be SI, SIR, or SEIR");
}
}
*/
// JHK Notes: HOW DO I GET THE CURRENT STEP??
//
// node >> graph
// graph >> scenario using SimulationManger method
// SimulationManger.getManger()
// then call manager.mapGraphToSimulation(final Graph graph) {
// to get the rvhp you just have to adapt it again.
// csv diseases read from file know their own
// time period property in millisecs
// This method is called by "updateLabels"
// should really override that instead fo compute transitions
// updateLabels has the TIME.
// TODO
// remove filter in StandardRelativeValueProviderAdapterFactory
// which is preventing disease deaths from being logged.
// method is StandardRelativeValueProviderAdapterFactory List<IItemPropertyDescriptor> getProperties()
StandardDiseaseModelLabelValue currentValue = (StandardDiseaseModelLabelValue)diseaseLabel.getCurrentValue();
// String id = ident.getURI().toString();
// int strt = id.indexOf(URI_PREFIX_PATTERN);
// if(strt>=0) {
// id = id.substring(strt+URI_PREFIX_PATTERN.length(),id.length());
// }
// if((dataInstance!=null)&&(dataInstance.instance.containsKey(id))) {
//if(dataInstance!=null) {
// compute the changes
if(adminLevel > -1) {
// First, if we do not know the various compartments etc used for the disease
// assume it's an SI, SIR or SEIR
if(streamer.getDecorator() == null) {
double deltaS = 0.0;
double deltaE = 0.0;
double deltaI = 0.0;
double deltaR = 0.0;
double incidence = 0.0;
// Population is not known so use the unknown key
population = CSVscenarioLoader.UNKNOWN_POP_IDENTIFIER_KEY;
List<Double>data = null;
if(streamer.getCurrentRow(population, adminLevel, labelS) < fileLineCounter)
data = streamer.streamRow(population, adminLevel, labelS);
else data = streamer.getLastFetchedRow(population, adminLevel, labelS);
int pos = streamer.getDataPosition(population, adminLevel, location);
if(data != null && pos >=0) {
double d = data.get(pos);
deltaS = d - currentValue.getS();
}// S
// Incidence
if(streamer.getCurrentRow(population, adminLevel, labelIncidence) < fileLineCounter)
data = streamer.streamRow(population, adminLevel, labelIncidence);
else data = streamer.getLastFetchedRow(population, adminLevel, labelIncidence);
if(data != null && pos >=0) {
double d = data.get(pos);
incidence = d;
}// S
if (diseaseType.equals(IMPORT_TYPE_SEIR)) {
if(streamer.getCurrentRow(population, adminLevel, labelE) < fileLineCounter)
data = streamer.streamRow(population, adminLevel, labelE);
else data = streamer.getLastFetchedRow(population, adminLevel, labelE);
if(data != null && pos >=0) {
double d = data.get(pos);
deltaE = d- ((SEIRLabelValue)currentValue).getE();
}// E
}
//////////////////////////////////////////////////////
// I
// May be more than one type of I state (Ia, Il, etc)
// for now just add them all up
//
int numIstates = I_KEY_SET.size();
if(I_KEY_SET!=null) {
Iterator<String> iter = I_KEY_SET.iterator();
double dI = 0;
while(iter.hasNext()) {
String iKey = iter.next();
if(streamer.getCurrentRow(population, adminLevel, iKey) < fileLineCounter)
data = streamer.streamRow(population, adminLevel, iKey);
else data = streamer.getLastFetchedRow(population, adminLevel, iKey);
if(data != null && pos >=0) {
double d = data.get(pos);
dI += d;
}
}
deltaI = dI - ((SILabelValue)currentValue).getI();
} else {
Activator.logInformation("I Keys are all Null !!");
}
//i
//////////////////////////////////////////////////////
if (diseaseType.equals(IMPORT_TYPE_SIR) || diseaseType.equals(IMPORT_TYPE_SEIR)) {
if(streamer.getCurrentRow(population, adminLevel, labelR) < fileLineCounter)
data = streamer.streamRow(population, adminLevel, labelR);
else data = streamer.getLastFetchedRow(population, adminLevel, labelR);
if(data != null && pos >=0) {
double d = data.get(pos);
deltaR = d - ((SIRLabelValue)currentValue).getR();
}// R
}
if (diseaseType.equals(IMPORT_TYPE_SI)) {
((SILabelValue)deltaState).setS(deltaS);
((SILabelValue)deltaState).setI(deltaI);
((SILabelValue)deltaState).setIncidence(incidence);
return new SILabelValueImpl( 0.0 , 0.0, 0.0, 0.0);
} else if (diseaseType.equals(IMPORT_TYPE_SIR)) {
((SIRLabelValue)deltaState).setS(deltaS);
((SIRLabelValue)deltaState).setI(deltaI);
((SIRLabelValue)deltaState).setR(deltaR);
((SIRLabelValue)deltaState).setIncidence(incidence);
return new SIRLabelValueImpl(0.0, 0.0 , 0.0, 0.0, 0.0);
} else if (diseaseType.equals(IMPORT_TYPE_SEIR)) {
((SEIRLabelValue)deltaState).setS(deltaS);
((SEIRLabelValue)deltaState).setE(deltaE);
((SEIRLabelValue)deltaState).setI(deltaI);
((SEIRLabelValue)deltaState).setR(deltaR);
((SEIRLabelValue)deltaState).setIncidence(incidence);
return new SEIRLabelValueImpl(0.0, 0.0, 0.0 , 0.0, 0.0, 0.0);
} else {
throw new UnsupportedOperationException("ExternalDataSource Invalid Type "+diseaseType+" must be SI, SIR, or SEIR");
}
} else {
List<Double>data = null;
// We have the property descriptors for the label value we need to set.
for(IItemPropertyDescriptor propDesc:propertyDescriptors.get(population)) {
// This is the name used in the CSV files
String dispName = propDesc.getDisplayName(propDesc);
int pos = streamer.getDataPosition(population, adminLevel, location);
if(streamer.getCurrentRow(population, adminLevel, dispName) < fileLineCounter)
data = streamer.streamRow(population, adminLevel, dispName);
else
data = streamer.getLastFetchedRow(population, adminLevel, dispName);
if(data != null && pos >= 0) {
double d = data.get(pos);
EStructuralFeature feature = (EStructuralFeature)propDesc.getFeature(null);
double currentVal = (Double)currentValue.eGet(feature);
if(!feature.isDerived() && feature.isChangeable())
deltaState.eSet(feature, d - currentVal);
}
}
}
}// admin level > -1
// }else {
// // if data == null
// // no data for location in questions
// if (diseaseType.equals(IMPORT_TYPE_SI)) {
// return new SILabelValueImpl(0.0 , 0.0, 0.0, 0.0);
// } else if (diseaseType.equals(IMPORT_TYPE_SIR)) {
// return new SIRLabelValueImpl(0.0, 0.0 , 0.0, 0.0, 0.0);
// } else if (diseaseType.equals(IMPORT_TYPE_SEIR)) {
// return new SEIRLabelValueImpl( 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0);
// } else {
// throw new UnsupportedOperationException("ExternalDataSource Invalid Type "+diseaseType+" must be SI, SIR, or SEIR");
// }
// }
} catch(IOException ioe) {
Activator.logError("Exception streaming data", ioe);
}
return null;
} // importDiseaseData
/**
* @see org.eclipse.stem.diseasemodels.standard.impl.DiseaseModelImpl#createDiseaseModelLabel()
*/
@Override
public DiseaseModelLabel createDiseaseModelLabel(String populationIdentifier) {
if(streamer.getDecorator() == null) {
if (diseaseType==IMPORT_TYPE_SI) return StandardFactory.eINSTANCE.createSILabel();
if (diseaseType==IMPORT_TYPE_SIR) return StandardFactory.eINSTANCE.createSIRLabel();
// else default
return StandardFactory.eINSTANCE.createSEIRLabel();
} else {
// We know the actual disease model used, call its methods to create the label
return ((DiseaseModel)streamer.getDecorator()).createDiseaseModelLabel(populationIdentifier);
}
} // createDiseaseModelLabel
/**
*
*/
@Override
public DiseaseModelLabelValue createDiseaseModelLabelValue(String populationIdentifier) {
if(streamer.getDecorator() == null) {
if(diseaseType==IMPORT_TYPE_SI) return StandardFactory.eINSTANCE.createSILabelValue();
if(diseaseType==IMPORT_TYPE_SIR) return StandardFactory.eINSTANCE.createSIRLabelValue();
return StandardFactory.eINSTANCE.createSEIRLabelValue();
} else {
// We know the actual disease model used, call its methods to create the label
return ((DiseaseModel)streamer.getDecorator()).createDiseaseModelLabelValue(populationIdentifier);
}
} // createDiseaseModelLabelValue
/**
* @see org.eclipse.stem.diseasemodels.standard.impl.DiseaseModelImpl#createInfector()
*/
@Override
public Infector createInfector() {
throw new UnsupportedOperationException();
} // createInfector
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated NOT
*/
public void addToTotalArea(double area) {
totalArea += area;
} // addToTotalArea
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated NOT
*/
public void addToTotalPopulationCount(double populationCount) {
totalPopulationCount += populationCount;
} // addToTotalPopulationCount
/**
* @param populationLabel
* the population label that labels the node
* @return the area of the node associated with the label
*/
public double getArea(final PopulationLabel populationLabel) {
double retValue = 0.0;
// The population label could have an area specified for the population
// that we should use instead of the area of the region labeled by the
// population label. This value would be specified if the population was
// densely packed into a small area of the larger region, for instance
// like a city in an otherwise large desert.
retValue = populationLabel.getPopulatedArea();
// Is there an area specified for the population?
if (retValue == 0.0) {
// No
// Ok, go find the area label and return the area of the region
for (final Iterator<NodeLabel> labelIter = populationLabel.getNode()
.getLabels().iterator(); labelIter.hasNext();) {
final NodeLabel nodeLabel = labelIter.next();
// Is this an area label?
if (nodeLabel instanceof AreaLabel) {
// Yes
final AreaLabel areaLabel = (AreaLabel) nodeLabel;
retValue = areaLabel.getCurrentAreaValue().getArea();
break;
}
} // for
} // If no population area specified
return retValue;
} // getArea
/**
* @param populationLabel
* @param area
*/
private void reportBadAreaValue(final PopulationLabel populationLabel,
double area) {
// The bad value could be specified for the node or be an overide
// value specified for the population.
// Is the bad value from the node?
if (populationLabel.getPopulatedArea() == 0.0) {
// Yes
Activator.logError("The area value of \"" + area
+ "\" specified for \""
+ populationLabel.getNode().toString()
+ "\" is not greater than zero (0.0)", null);
} // if bad value for node area
else {
Activator.logError("The area value of \"" + area
+ "\" specified for the population \""
+ populationLabel.getPopulationIdentifier() + "\" for the region \""
+ populationLabel.getNode().toString()
+ "\" is not greater than zero (0.0)", null);
}
} // reportBadAreaValue
@Override
public EList<String> getAllLabelIdentifiers() {
List<String> popIds = this.streamer.getPopulationIdentifiers();
EList<String> identifiers = new BasicEList<String>();
if(popIds != null)
for (String pop : popIds) {
identifiers.add(pop);
}
else identifiers.add(this.getPopulationIdentifier());
return identifiers;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return ExternalDataSourcePackage.Literals.EXTERNAL_DATA_SOURCE_DISEASE_MODEL;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getDataPath() {
return dataPath;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setDataPath(String newDataPath) {
String oldDataPath = dataPath;
dataPath = newDataPath;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ExternalDataSourcePackage.EXTERNAL_DATA_SOURCE_DISEASE_MODEL__DATA_PATH, oldDataPath, dataPath));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getDiseaseType() {
return diseaseType;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setDiseaseType(String newDiseaseType) {
String oldDiseaseType = diseaseType;
diseaseType = newDiseaseType;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ExternalDataSourcePackage.EXTERNAL_DATA_SOURCE_DISEASE_MODEL__DISEASE_TYPE, oldDiseaseType, diseaseType));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case ExternalDataSourcePackage.EXTERNAL_DATA_SOURCE_DISEASE_MODEL__DATA_PATH:
return getDataPath();
case ExternalDataSourcePackage.EXTERNAL_DATA_SOURCE_DISEASE_MODEL__DISEASE_TYPE:
return getDiseaseType();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case ExternalDataSourcePackage.EXTERNAL_DATA_SOURCE_DISEASE_MODEL__DATA_PATH:
setDataPath((String)newValue);
return;
case ExternalDataSourcePackage.EXTERNAL_DATA_SOURCE_DISEASE_MODEL__DISEASE_TYPE:
setDiseaseType((String)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case ExternalDataSourcePackage.EXTERNAL_DATA_SOURCE_DISEASE_MODEL__DATA_PATH:
setDataPath(DATA_PATH_EDEFAULT);
return;
case ExternalDataSourcePackage.EXTERNAL_DATA_SOURCE_DISEASE_MODEL__DISEASE_TYPE:
setDiseaseType(DISEASE_TYPE_EDEFAULT);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case ExternalDataSourcePackage.EXTERNAL_DATA_SOURCE_DISEASE_MODEL__DATA_PATH:
return DATA_PATH_EDEFAULT == null ? dataPath != null : !DATA_PATH_EDEFAULT.equals(dataPath);
case ExternalDataSourcePackage.EXTERNAL_DATA_SOURCE_DISEASE_MODEL__DISEASE_TYPE:
return DISEASE_TYPE_EDEFAULT == null ? diseaseType != null : !DISEASE_TYPE_EDEFAULT.equals(diseaseType);
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String toString() {
if (eIsProxy()) return super.toString();
StringBuffer result = new StringBuffer(super.toString());
result.append(" (dataPath: "); //$NON-NLS-1$
result.append(dataPath);
result.append(", diseaseType: "); //$NON-NLS-1$
result.append(diseaseType);
result.append(')');
return result.toString();
}
/**
* Since data is read from a file we don't have to take into account
* birth/deaths etc from other decorators, the data is already supposed
* to handle that.
*/
public void applyExternalDeltas(STEMTime time, long timeDelta,
EList<DynamicLabel> labels) {
// Nothing to do.
}
public synchronized void calculateDelta(STEMTime time, long timeDelta,
EList<DynamicLabel> labels) {
if(firstSTEMTime == null || time.getTime().equals(firstSTEMTime.getTime()))
fileLineCounter = 1;
else
fileLineCounter = (int)((time.getTime().getTime() - firstSTEMTime.getTime().getTime()) / timeDelta)+1;
if(firstSTEMTime == null) firstSTEMTime = time;
// Iterate through each of the labels we need to update.
for (final DynamicLabel dynLabel : labels) {
final StandardDiseaseModelLabel diseaseLabel = (StandardDiseaseModelLabel) dynLabel;
// This is the current state of the disease for this label
final StandardDiseaseModelLabelValue deltaState = (StandardDiseaseModelLabelValue)diseaseLabel
.getDeltaValue();
// 2) This will set the delta
final StandardDiseaseModelLabelValue nullAdditions = importDiseaseData(deltaState, diseaseLabel, time, timeDelta);
} // for
}
public void doModelSpecificAdjustments(LabelValue label) {
// TODO Auto-generated method stub
}
public boolean isDeterministic() {
return true;
}
@Override
public StandardDiseaseModelLabelValue computeDiseaseDeltas(STEMTime time, double t,
StandardDiseaseModelLabelValue currentState,
StandardDiseaseModelLabel diseaseLabel, long timeDelta,
DiseaseModelLabelValue returnValue) {
// Nothing to do
return (StandardDiseaseModelLabelValue)returnValue;
}
} //ExternalDataSourceDiseaseModelImpl