Skip to content

Commit

Permalink
publish quokka MSW time estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
nxi authored and nxi committed Mar 31, 2015
1 parent d7ec9a5 commit d23d881
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 33 deletions.
Expand Up @@ -1407,7 +1407,11 @@ public void focusGained(FocusEvent e) {
if (parameter.getProperty("title") != null) {
name.setText(parameter.getProperty("title"));
} else {
name.setText(parameter.getName());
if (parameter.getName() != null) {
name.setText(parameter.getName());
} else {
name.setText("");
}
}
GridDataFactory.fillDefaults().grab(false, false).indent(0, 3).minSize(40, 0).align(SWT.END, SWT.CENTER).span(parameterColspan, parameterRowspan).applyTo(name);
final Text floatText = new Text(parent, SWT.BORDER);
Expand Down
Expand Up @@ -232,6 +232,13 @@ var refresh = function(){
} else {
$("#" + devices[i].items[j].classId).text(obj.hdbs[k].value + " " + devices[i].items[j].units);
}
if (devices[i].items[j].colorList != null) {
$.each(devices[i].items[j].colorList, function(key, value) {
if (obj.hdbs[k].value == key) {
$("#" + devices[i].items[j].classId).css("color", value);
}
});
}
} catch (e) {
}
break;
Expand Down
Expand Up @@ -62,6 +62,8 @@ public class Experiment extends AbstractModelObject {
// Optional directory destination for exporting user report
private String userReportDirectory;

private boolean isRunning = false;

/*************************************************************************
* Dynamic settings (objects created and destroyed during configuration)
*************************************************************************/
Expand Down Expand Up @@ -459,4 +461,16 @@ public String toString() {
+ user + ", userReportDirectory=" + userReportDirectory + "]";
}

public void update() {
firePropertyChange("", null, null);
}

public boolean isRunning() {
return isRunning;
}

public void setRunning(boolean isRunning) {
this.isRunning = isRunning;
}

}
Expand Up @@ -282,15 +282,16 @@ public static void refineExperimentFromExcel(Experiment experiment,

public static long calculateEstimatedRunTime(Experiment experiment) {
long counter = 0;
boolean isRunning = experiment.isRunning();
if (experiment.isControlledEnvironment()) {
for (ControlledAcquisition acquistion : experiment.getAcquisitionGroups()) {
for (AcquisitionEntry entry : acquistion.getEntries()) {
counter += calculateEstimatedRunTime(entry);
counter += calculateEstimatedRunTime(entry, isRunning);
}
}
} else {
for (AcquisitionEntry entry : experiment.getNormalAcquisition().getEntries()) {
counter += calculateEstimatedRunTime(entry);
counter += calculateEstimatedRunTime(entry, isRunning);
}
}
return counter;
Expand All @@ -301,12 +302,13 @@ public static long calculateEstimatedRunTime(Experiment experiment) {
// * Configuration changing time
// * Voltage controller time
// * Sample environment drive time
private static long calculateEstimatedRunTime(AcquisitionEntry entry) {
private static long calculateEstimatedRunTime(AcquisitionEntry entry, boolean isRunning) {
long counter = 0;
for (Entry<InstrumentConfig, AcquisitionSetting> settingEntry : entry.getConfigSettings().entrySet()) {
InstrumentConfig config = settingEntry.getKey();
AcquisitionSetting setting = settingEntry.getValue();
// Add transmission time
// if (setting.isRunTransmission() && (isRunning ? setting.getTransmissionDataFile() == null : true)) {
if (setting.isRunTransmission()) {
if (config.getTransmissionMode() == ScanMode.TIME) {
// time mode
Expand All @@ -320,6 +322,7 @@ private static long calculateEstimatedRunTime(AcquisitionEntry entry) {
}
}
// Add scattering time
// if (setting.isRunScattering() && (isRunning ? setting.getScatteringDataFile() == null : true)) {
if (setting.isRunScattering()) {
if (config.getMode() == ScanMode.TIME) {
// time mode
Expand All @@ -343,26 +346,29 @@ public static long calculateEstimatedConfigTime(Experiment experiment) {
// Beamstop move time (20 sec up or down for config)
counter += experiment.getInstrumentConfigs().size() * 20 * 2;

boolean isRunning = experiment.isRunning();

if (experiment.isControlledEnvironment()) {
for (ControlledAcquisition acquistion : experiment.getAcquisitionGroups()) {
for (AcquisitionEntry entry : acquistion.getEntries()) {
counter += calculateEstimatedConfigTime(entry);
counter += calculateEstimatedConfigTime(entry, isRunning);
}
}
} else {
for (AcquisitionEntry entry : experiment.getNormalAcquisition().getEntries()) {
counter += calculateEstimatedConfigTime(entry);
counter += calculateEstimatedConfigTime(entry, isRunning);
}
}
return counter;
}

private static long calculateEstimatedConfigTime(AcquisitionEntry entry) {
private static long calculateEstimatedConfigTime(AcquisitionEntry entry, boolean isRunning) {
long counter = 0;
for (Entry<InstrumentConfig, AcquisitionSetting> settingEntry : entry.getConfigSettings().entrySet()) {
InstrumentConfig config = settingEntry.getKey();
AcquisitionSetting setting = settingEntry.getValue();
// Add scattering time
// if (setting.isRunScattering() && (isRunning ? setting.getScatteringDataFile() == null : true)) {
if (setting.isRunScattering()) {
// [GUMTREE-800]
// Attenuation is in the step of 30 deg, and we assume each step takes 35 sec
Expand Down
Expand Up @@ -66,7 +66,9 @@
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.statushandlers.StatusManager;
import org.gumtree.core.service.ServiceUtils;
import org.gumtree.gumnix.sics.core.ISicsManager;
import org.gumtree.gumnix.sics.core.SicsCore;
import org.gumtree.gumnix.sics.io.ISicsCallback;
import org.gumtree.gumnix.sics.io.SicsIOException;
import org.gumtree.scripting.IScriptBlock;
import org.gumtree.scripting.IScriptExecutor;
Expand Down Expand Up @@ -115,6 +117,10 @@ public class AcquisitionTask extends AbstractExperimentTask {

private Shell currentShell;

private long timestampOnEstimation;

// private int estimatedTimeForBuffer;

@Override
protected ITaskView createViewInstance() {
view = new AcquisitionTaskView();
Expand All @@ -133,11 +139,6 @@ public Object run(Object input) {
return null;
}

/*********************************************************************
* Update estimate
*********************************************************************/
view.upateTimeEstimation();

/*********************************************************************
* Clear previous result
*********************************************************************/
Expand Down Expand Up @@ -201,25 +202,44 @@ public String getScript() {
return script;
}
};
executor.runScript(block);

// Not thread safe! We need listener model instead!
// Wait until it gets busy
LoopRunner.run(new ILoopExitCondition() {
@Override
public boolean getExitCondition() {
return executor.isBusy();
}
}, 5000, 10);
getExperiment().setRunning(true);

// Check execution status every 1 sec
LoopRunner.run(new ILoopExitCondition() {
@Override
public boolean getExitCondition() {
return !executor.isBusy();
}
}, LoopRunner.NO_TIME_OUT, 1000);

/*********************************************************************
* Update estimate
*********************************************************************/
timestampOnEstimation = System.currentTimeMillis();

view.updateTimeEstimation(true);


try{
executor.runScript(block);

// Not thread safe! We need listener model instead!
// Wait until it gets busy
LoopRunner.run(new ILoopExitCondition() {
@Override
public boolean getExitCondition() {
return executor.isBusy();
}
}, 5000, 10);

// Check execution status every 1 sec
LoopRunner.run(new ILoopExitCondition() {
@Override
public boolean getExitCondition() {
return !executor.isBusy();
}
}, LoopRunner.NO_TIME_OUT, 1000);

} catch(Exception e) {
logger.error("Error in running script with python engine.");
} finally {
getExperiment().setRunning(false);

view.updateTimeEstimation(true);
}
/*****************************************************************
* Export
*****************************************************************/
Expand Down Expand Up @@ -1029,6 +1049,14 @@ public void run() throws Exception {
});
}
});

getExperiment().addPropertyChangeListener(new PropertyChangeListener() {

@Override
public void propertyChange(PropertyChangeEvent arg0) {
updateTimeEstimation(true);
}
});
}

private void createTableButtonArea(Composite parent) {
Expand Down Expand Up @@ -1107,12 +1135,12 @@ private void createStatusArea(Composite parent) {
Button updateButton = getToolkit().createButton(parent, "Update", SWT.PUSH);
updateButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
upateTimeEstimation();
updateTimeEstimation(false);
}
});
}

private void upateTimeEstimation() {
private void updateTimeEstimation(final boolean doReport) {
SafeUIRunner.asyncExec(new SafeRunnable() {
public void run() throws Exception {
long runtTime = ExperimentModelUtils.calculateEstimatedRunTime(getExperiment());
Expand All @@ -1121,10 +1149,46 @@ public void run() throws Exception {
configText.setText(StringUtils.formatTime(configTime));
long totalTime = runtTime + configTime;
totalText.setText(StringUtils.formatTime(totalTime));
if (doReport) {
reportTimeEstimation((int) totalTime);
reportGumtreeStatus();
}
}
});
}

private void reportTimeEstimation(int totalTime) throws SicsIOException{
if (totalTime == 0) {
asyncSend("hset /experiment/gumtree_time_estimate 0", null, "status");
return;
}
if (getExperiment().isRunning()) {
long finishTime = timestampOnEstimation / 1000 + totalTime;
// time += estimatedTimeForBuffer - (System.currentTimeMillis() - timestampOnEstimation) / 1000;

asyncSend("hset /experiment/gumtree_time_estimate " + finishTime, null, "status");
} else {
asyncSend("hset /experiment/gumtree_time_estimate 0", null, "status");
}
}

private void reportGumtreeStatus() throws SicsIOException {
if (getExperiment().isRunning()) {
asyncSend("gumtree_status BUSY", null, "status");
} else {
asyncSend("gumtree_status IDLE", null, "status");
}
}

private void asyncSend(String command, ISicsCallback callback,
String channelId) throws SicsIOException {
ISicsManager sicsManager = SicsCore.getSicsManager();
if (sicsManager != null) {
sicsManager.proxy().send(command, callback, channelId);
}
System.err.println(command);
}

private void fireLiveReductionRequest(int col, int row) {
AcquisitionSetting setting = ((ScanTableModel) table.getModel()).getAcquisitionSetting(col, row);
if (setting != null) {
Expand Down Expand Up @@ -1155,6 +1219,7 @@ private void updateUI(Acquisition acquisition) {
} else {
updateNormalAcquisitionUI(acquisition);
}
updateTimeEstimation(true);
}
}

Expand Down
Expand Up @@ -484,6 +484,7 @@ public void run() throws Exception {
}
}
}
experiment.update();
}
/**
* Helper method to retrieve the associated setting from a cell.
Expand Down
Expand Up @@ -7,8 +7,8 @@ var devices = [
// "items":[{"classId":"gumtree_time_estimate", "deviceId":"gumtree_time_estimate", "title":"Expected Finishing Time", "units":"", "adapt" : getTimeString}
// ]
// },
{"group":"GUMTREE BUFFER QUEUE",
"items":[{"classId":"gumtree_status", "deviceId":"gumtree_status", "title":"Status", "units":""}
{"group":"GUMTREE MULTI-SAMPLE WORKFLOW",
"items":[{"classId":"gumtree_status", "deviceId":"gumtree_status", "title":"Status", "units":"", "colorList":{"BUSY":"#FFA500", "IDLE":"#00c400"}}
]
},
{"group":"BEAM STATUS",
Expand Down

0 comments on commit d23d881

Please sign in to comment.