CoRoT N3 Variability¶
Le CoRoT N3 Variability permet de faire une requête en prenant en compte ou non certaines observations d'après leur probabilité N3 : delta scuti, etc... et la valeur de la probabilité entre 0 et 1.
Le code javascript correspondant :
Côté ADMIN :
/*global Ext, sitools, ID, i18n, document, showResponse, alertFailure, LOCALE, ImageChooser,
showHelp*/
Ext.namespace('sitools.component.forms.multiParam');
sitools.component.forms.multiParam.NthreeVariability = Ext.extend(sitools.component.forms.multiParam.abstractForm, {
height : 250,
id : 'sitools.component.forms.definitionId',
initComponent : function () {
this.winPropComponent.specificHeight = 350;
this.winPropComponent.specificWidth = 450;
sitools.component.forms.multiParam.NthreeVariability.superclass.initComponent.call(this);
this.componentDefaultValue1 = new Ext.form.NumberField({
fieldLabel : i18n.get('label.defaultValue') + ' (Proba)',
name : 'componentDefaultValue1',
anchor : '100%',
allowBlank : true
});
this.add(this.componentDefaultValue1);
},
onRender : function () {
sitools.component.forms.multiParam.NthreeVariability.superclass.onRender.apply(this, arguments);
if (this.action == 'modify') {
if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) {
if (Ext.isString(this.selectedRecord.data.defaultValues[0])) {
this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0]);
}
}
}
},
afterRender : function () {
sitools.component.forms.multiParam.NthreeVariability.superclass.afterRender.apply(this, arguments);
if (this.action == 'modify') {
if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) {
this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0]);
}
}
},
_onValidate : function (action, gridFormComponents) {
var f = this.getForm();
if (!f.isValid()) {
Ext.Msg.alert(i18n.get('label.error'), i18n.get('warning.invalidForm'));
return false;
}
var defaultValue1 = Ext.isEmpty(f.findField('componentDefaultValue1')) ? "" : f.findField('componentDefaultValue1').getValue();
var columnObjects = this.find('specificType', 'mapParam');
var code = [];
Ext.each(columnObjects, function (columnObject) {
code.push(columnObject.getValue());
});
if (action == 'modify') {
var rec = gridFormComponents.getSelectionModel().getSelected();
var labelParam1 = Ext.isEmpty(f.findField('LABEL_PARAM1')) ? "" : f.findField('LABEL_PARAM1').getValue();
var css = Ext.isEmpty(f.findField('CSS')) ? "" : f.findField('CSS').getValue();
rec.set('label', labelParam1);
rec.set('code', code);
rec.set('css', css);
rec.set('componentDefaultHeight', f.findField('componentDefaultHeight').getValue());
rec.set('componentDefaultWidth', f.findField('componentDefaultWidth').getValue());
rec.set('defaultValues', [ defaultValue1 ]);
} else {
var formComponentsStore = gridFormComponents.getStore();
// Génération de l'id
var lastId = 0;
var greatY = 0;
formComponentsStore.each(function (component) {
if (component.data.id > lastId) {
lastId = parseInt(component.data.id, 10);
}
if (component.data.ypos > greatY) {
greatY = parseInt(component.data.ypos, 10) + parseInt(component.data.height, 10);
}
});
var componentId = lastId + 1;
componentId = componentId.toString();
var componentYpos = greatY + 10;
formComponentsStore.add(new Ext.data.Record({
label : f.findField('LABEL_PARAM1').getValue(),
type : this.ctype,
code : code,
width : f.findField('componentDefaultWidth').getValue(),
height : f.findField('componentDefaultHeight').getValue(),
id : componentId,
ypos : componentYpos,
css : f.findField('CSS').getValue(),
jsAdminObject : this.jsAdminObject,
jsUserObject : this.jsUserObject,
defaultValues : [ defaultValue1 ]
}));
}
return true;
}
});
Côté CLIENT :
/***************************************
* Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
*
* This file is part of SITools2.
*
* SITools2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SITools2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SITools2. If not, see <http://www.gnu.org/licenses/>.
***************************************/
/*global Ext, sitools*/
Ext.ns('sitools.component.users.SubSelectionParameters.SingleSelection');
sitools.component.users.SubSelectionParameters.SingleSelection.NthreeVariability = Ext.extend(Ext.Container, {
initComponent : function () {
var defaultValue = "", value, items=[];
items.push(['pvsg', 'Periodically variable supergiants']);
items.push(['be', 'Variable Be-stars']);
items.push(['bcep', 'Beta-Cephei stars']);
items.push(['clcep', 'Classical Cepheids']);
items.push(['cp', 'Chemically peculiar stars']);
items.push(['dscut', 'Delta-Scuti stars']);
items.push(['ell', 'Ellipsoidal variables']);
items.push(['gdor', 'Gamma-Doradus stars']);
items.push(['haebe', 'Herbig Ae/Be stars']);
items.push(['xb', 'X-ray binaries']);
items.push(['lboo', 'Lambda-Bootis variables']);
items.push(['lbv', 'Luminous Blue variables']);
items.push(['mira', 'Mira variables']);
items.push(['ptcep', 'Population II Cepheids']);
items.push(['spds', 'Short Period Delta-Scuti']);
items.push(['rrab', 'RR-Lyrae stars, subtype ab']);
items.push(['rrc', 'RR-Lyrae stars, subtype c']);
items.push(['rvtau', 'RV-Tauri stars']);
items.push(['sr', 'Semi-regular variables']);
items.push(['spb', 'Slowly Pulsating B-stars']);
items.push(['sxphe', 'SX-Phe stars']);
items.push(['ttau', 'T-Tauri stars']);
items.push(['wr', 'Wolf-Rayet stars']);
items.push(['fuori', 'FU-Ori stars']);
items.push(['sdbv', 'Pulsating subdwarf B-stars']);
items.push(['ecl', 'Eclipsing binaries (all types)']);
items.push(['rrd', 'Double mode RR-Lyrae stars']);
items.push(['dmcep', 'Double-mode Cepheids']);
items.push(['lapv', 'Low-Amplitude Periodic Variables']);
var defaultProba = this.defaultValues[0];
var store;
store = new Ext.data.ArrayStore({
fields : [ 'id', 'value' ],
data : items
});
this.combo = new Ext.form.ComboBox ({
store : store,
parameterId : this.parameterId,
sParentParam : this.parentParam,
valueField : 'id',
displayField : 'value',
typeAhead : true,
mode : 'local',
triggerAction : 'all',
selectOnFocus : true,
allowBlank : true,
editable : false,
autoSelect : false,
height : this.height,
value : defaultValue,
tpl : '<tpl for="."><div class="x-combo-list-item comboItem">{value}</div></tpl>',
stype : "sitoolsFormItem",
/**
* The Parent Window.
*/
parent : "panelResultForm" + this.formId,
/**
* The code of the parameter to notify changed event.
*/
code : this.code,
anchor : '90%',
listeners : {
scope : this,
'select' : function () {
var parentPanel = this.ownerCt.ownerCt;
parentPanel.fireEvent('componentChanged', parentPanel, this);
}
}
});
this.probaParam = new Ext.form.NumberField({
fieldLabel : "proba",
allowBlank : true,
decimalPrecision : 20,
anchor : "98%",
value : defaultProba,
});
Ext.apply(this, {
stype : "sitoolsFormContainer",
layout : "hbox",
items : [new Ext.Container({
border : false,
html : this.label,
width : 70
}), this.combo, new Ext.Container({border : false,
html : ' '}), new Ext.Container({
border : false,
html : 'Probabilité (0.0 -> 1.0) : ',
width : 70
}), this.probaParam,
new Ext.Container({
border : false,
html : ' '
})
]
});
sitools.component.users.SubSelectionParameters.SingleSelection.NthreeVariability.superclass.initComponent.apply(this,
arguments);
},
notifyValueSelected : function () {
this.parent.notifyValueChanged(this.code);
},
isValueDefined : function () {
if (this.combo.getValue() && this.combo.getValue() !== "") {
return true;
} else {
return false;
}
},
getSelectedValue : function () {
if (this.combo.getValue() && this.combo.getValue() !== "") {
return this.combo.getValue();
} else {
return null;
}
},
setSelectedValue : function (value) {
this.combo.setValue(value);
},
getParameterValue : function () {
var value = this.getSelectedValue();
if (Ext.isEmpty(value)) {
return null;
}
var probaval = this.probaParam.getValue();
if(Ext.isEmpty(probaval) || probaval == ""){
probaval='0.0';
}
return this.type + "|" + value + "|" + probaval;
}
});
Code JAVA à inclure dans workspace/fr.cnes.sitools.extensions/src/fr/cnes/sitools/filter et référencer la classe dans le fichier fr.cnes.sitools.filter.FilterHelper
/*******************************************************************************
* Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
*
* This file is part of SITools2.
*
* SITools2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SITools2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SITools2. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package fr.cnes.sitools.filter.basic;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import org.restlet.Request;
import org.restlet.data.Form;
import org.restlet.ext.wadl.ParameterInfo;
import org.restlet.ext.wadl.ParameterStyle;
import fr.cnes.sitools.common.validator.ConstraintViolation;
import fr.cnes.sitools.common.validator.Validator;
import fr.cnes.sitools.dataset.DataSetApplication;
import fr.cnes.sitools.dataset.filter.business.AbstractFilter;
import fr.cnes.sitools.dataset.model.Column;
import fr.cnes.sitools.dataset.model.DataSet;
import fr.cnes.sitools.dataset.model.Operator;
import fr.cnes.sitools.dataset.model.Predicat;
import fr.cnes.sitools.util.SQLUtils;
/**
* Filter defined for Single Value Component
*
*
* @author d.arpin
*/
public final class NThreeVariability extends AbstractFilter {
/**
* The index of TYPE
*/
private static final int TYPE = 0;
/**
* The index of COLUMN
*/
private static final int COLUMN = 1;
/**
* The index of Values
*/
private static final int VALUES = 2;
/**
* The list of component that uses this filter
*/
private enum TYPE_COMPONENT {
/** Boolean Custom type */
NTHREE_VARIABILITY
}
/** The TEMPLATE_PARAM */
private static final String TEMPLATE_PARAM = "p[#]";
/**
* Default constructor
*/
public NThreeVariability() {
super();
this.setName("NThreeVariability");
this.setDescription("Required when using NThreeVariability Component");
this.setAuthor("Matthieu Husson");
this.setClassAuthor("IAS");
this.setClassOwner("MH@IAS");
this.setVersion("0.1");
this.setDefaultFilter(true);
HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>();
ParameterInfo paramInfo;
paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY, "NTHREE_VARIABILITY|columnAlias|value");
rpd.put("0", paramInfo);
this.setRequestParamsDescription(rpd);
}
@Override
public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception {
DataSetApplication dsApplication = null;
DataSet ds = null;
Form params = request.getResourceRef().getQueryAsForm();
boolean filterExists = true;
int i = 0;
// Build predicat for filters param
while (filterExists) {
String index = TEMPLATE_PARAM.replace("#", Integer.toString(i++));
String formParam = params.getFirstValue(index);
if (formParam != null) {
String[] parameters = formParam.split("\\|");
TYPE_COMPONENT[] types = TYPE_COMPONENT.values();
Boolean trouve = false;
for (TYPE_COMPONENT typeCmp : types) {
if (typeCmp.name().equals(parameters[TYPE])) {
trouve = true;
}
}
if (trouve) {
if (dsApplication == null) {
dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication");
ds = dsApplication.getDataSet();
}
String columnAlias = null;
if (parameters.length >= VALUES) {
columnAlias = parameters[COLUMN];
System.out.println("\ncolumn : " + columnAlias);
Column col = ds.findByColumnAlias(columnAlias);
if (col != null && col.getFilter() != null && col.getFilter()) {
// get the value and escape it to avoid SQL injection
String value = SQLUtils.escapeString(parameters[VALUES]);
Predicat predicat = new Predicat();
if (value != null) {
predicat.setLeftAttribute(col);
predicat.setNbOpenedParanthesis(0);
predicat.setNbClosedParanthesis(0);
predicat.setCompareOperator(Operator.GT.value());
predicat.setRightValue("'" + value + "'");
System.out.println("\nvalue : " + value);
predicats.add(predicat);
}
}
}
}
}
else {
filterExists = false;
}
}
return predicats;
}
/**
* Gets the validator for this Filter
*
* @return the validator for the filter
*/
@Override
public Validator<AbstractFilter> getValidator() {
return new Validator<AbstractFilter>() {
@Override
public Set<ConstraintViolation> validate(AbstractFilter item) {
return null;
}
};
}
}