<commit_before>package org.waterforpeople.mapping.surveyentry.client.component;

import org.apache.tools.ant.listener.AnsiColorLogger;
import org.waterforpeople.mapping.app.gwt.client.survey.QuestionDto;
import org.waterforpeople.mapping.app.gwt.client.surveyinstance.QuestionAnswerStoreDto;

import com.gallatinsystems.framework.gwt.util.client.ViewUtil;
import com.google.gwt.user.client.ui.TextBox;

/**
 * 
 * handles geo questions
 * 
 * @author <NAME>
 * 
 */
public class GeoQuestionWidget extends QuestionWidget {
	private static final String TYPE = "GEO";
	private static final String DELIM = "|";
	private TextBox lat;
	private TextBox lon;
	private TextBox alt;
	private TextBox code;

	public GeoQuestionWidget(QuestionDto q, QuestionAnswerStoreDto a) {
		super(q,a);
	}

	@Override
	protected void constructResponseUi() {
		lat = new TextBox();
		ViewUtil.installFieldRow(getPanel(), "Latitude", lat, null);
		lon = new TextBox();
		ViewUtil.installFieldRow(getPanel(), "Longitude", lon, null);
		alt = new TextBox();
		ViewUtil.installFieldRow(getPanel(), "Altitude", alt, null);
		code = new TextBox();
		ViewUtil.installFieldRow(getPanel(), "Code", code, null);
		if(getAnswer().getKeyId() != null){
			//if we're initializing and key id is not null, prepopulate
			
		}
	}

	public void captureAnswer() {
		getAnswer().setType(TYPE);
		StringBuilder value = new StringBuilder();
		// answers don't count unless lat and lon are captured
		if (ViewUtil.isTextPopulated(lat) && ViewUtil.isTextPopulated(lon)) {
			value.append(lat.getText().trim()).append(DELIM).append(
					lon.getText().trim()).append(DELIM);
			value.append(
					ViewUtil.isTextPopulated(alt) ? alt.getText().trim() : "")
					.append(DELIM);
			value.append(ViewUtil.isTextPopulated(code) ? code.getText().trim()<commit_msg>added handling of geo questions to form.<commit_after>package org.waterforpeople.mapping.surveyentry.client.component;

import org.apache.tools.ant.listener.AnsiColorLogger;
import org.waterforpeople.mapping.app.gwt.client.survey.QuestionDto;
import org.waterforpeople.mapping.app.gwt.client.surveyinstance.QuestionAnswerStoreDto;

import com.gallatinsystems.framework.gwt.util.client.ViewUtil;
import com.google.gwt.user.client.ui.TextBox;

/**
 * 
 * handles geo questions
 * 
 * @author <NAME>
 * 
 */
public class GeoQuestionWidget extends QuestionWidget {
	private static final String TYPE = "GEO";
	private static final String DELIM = "|";
	private static final String DELIM_REGEX  = "\\|";
	private TextBox lat;
	private TextBox lon;
	private TextBox alt;
	private TextBox code;

	public GeoQuestionWidget(QuestionDto q, QuestionAnswerStoreDto a) {
		super(q,a);
	}

	@Override
	protected void constructResponseUi() {
		lat = new TextBox();
		ViewUtil.installFieldRow(getPanel(), "Latitude", lat, null);
		lon = new TextBox();
		ViewUtil.installFieldRow(getPanel(), "Longitude", lon, null);
		alt = new TextBox();
		ViewUtil.installFieldRow(getPanel(), "Altitude", alt, null);
		code = new TextBox();
		ViewUtil.installFieldRow(getPanel(), "Code", code, null);
		if(getAnswer().getKeyId() != null){
			//if we're initializing and key id is not null, pre-populate
			String val = getAnswer().getValue();
			if(val != null){
				String[] valParts = val.split(DELIM_REGEX);
				if(valParts.length>=2){
					lat.setValue(valParts[0]);
					lon.setValue(valParts[1]);
				}
				if(valParts.length>=3){
					alt.setValue(valParts[2]);
				}
				if(valParts.length>=4){
					code.setValue(valParts[3]);
				}
			}
			
		}
	}

	public void captureAnswer() {
		getAnswer().setType(TYPE);
		StringBuilder value = new StringBuilder();
		// answers don't count unless lat and lon are captured
		if (ViewUtil.isTextPopulated(lat) && ViewUtil.isTextPopulated(lon)) {
			value.append(lat.getText().trim()).append(DELIM).append(
					lon.getText().trim()).append(DELIM);
			value.append(
					ViewUtil.isTextPopulated(alt) ? alt.getText().trim() : "")
					.append(DELIM);
			value.append(ViewUtil.isTextPopulated(code) ? code.getText().trim()
{'fraction_non_alphanumeric': 0.13943139678615574, 'fraction_numerical': 0.00173053152039555, 'mean_word_length': 4.60387811634349, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5650335', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1279, 'n_words': 271}