<commit_before>/*
 * Copyright 2017 Open mHealth
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openmhealth.shim.moves.mapper;

import com.fasterxml.jackson.databind.JsonNode;
import org.openmhealth.schema.domain.omh.DataPointModality;
import org.openmhealth.schema.domain.omh.SchemaSupport;
import org.openmhealth.schema.domain.omh.TimeFrame;
import org.openmhealth.shim.common.mapper.JsonNodeDataPointMapper;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;

import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED;
import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED;
import static org.openmhealth.schema.domain.omh.TimeInterval.ofStartDateTimeAndEndDateTime;
import static org.openmhealth.shim.common.mapper.JsonNodeMappingSupport.asOptionalBoolean;
import static org.openmhealth.shim.common.mapper.JsonNodeMappingSupport.asRequiredOffsetDateTime;


/**
 * The base class for mappers that translate Moves API responses to data points.
 *
 * @author <NAME>
 * @author <NAME>
 */
public abstract class MovesDataPointMapper<T extends SchemaSupport> implements JsonNodeDataPointMapper<T> {

    public static final String RESOURCE_API_SOURCE_NAME = "Moves Resource API";

    protected static final DateTimeFormatter OFFSET_DATE_TIME_FORMATTER =
            DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmsszzzzz");


    /**
     * @param node a node containing "startTime" and "endTime" fields
     * @return the equivalent time frame
     */
    public TimeFrame getTimeFrame(JsonNode node) {

        OffsetDateTime startDateTime = asRequiredOffsetDateTime(node, "startTime", OFFSET_DATE_TIME_FORMATTER);
        OffsetDateTime endDateTime = asRequiredOffsetDateTime(node, "endTime", OFFSET_DATE_TIME_FORMATTER);

        return new TimeFrame(ofStartDateTimeAndEndDateTime(startDateTime, endDateTime));<commit_msg>Fix Moves date time parser<commit_after>/*
 * Copyright 2017 Open mHealth
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openmhealth.shim.moves.mapper;

import com.fasterxml.jackson.databind.JsonNode;
import org.openmhealth.schema.domain.omh.DataPointModality;
import org.openmhealth.schema.domain.omh.SchemaSupport;
import org.openmhealth.schema.domain.omh.TimeFrame;
import org.openmhealth.shim.common.mapper.JsonNodeDataPointMapper;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;

import static org.openmhealth.schema.domain.omh.DataPointModality.SELF_REPORTED;
import static org.openmhealth.schema.domain.omh.DataPointModality.SENSED;
import static org.openmhealth.schema.domain.omh.TimeInterval.ofStartDateTimeAndEndDateTime;
import static org.openmhealth.shim.common.mapper.JsonNodeMappingSupport.asOptionalBoolean;
import static org.openmhealth.shim.common.mapper.JsonNodeMappingSupport.asRequiredOffsetDateTime;


/**
 * The base class for mappers that translate Moves API responses to data points.
 *
 * @author <NAME>
 * @author <NAME>
 */
public abstract class MovesDataPointMapper<T extends SchemaSupport> implements JsonNodeDataPointMapper<T> {

    public static final String RESOURCE_API_SOURCE_NAME = "Moves Resource API";

    protected static final DateTimeFormatter OFFSET_DATE_TIME_FORMATTER =
            DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssZZZZZ");


    /**
     * @param node a node containing "startTime" and "endTime" fields
     * @return the equivalent time frame
     */
    public TimeFrame getTimeFrame(JsonNode node) {

        OffsetDateTime startDateTime = asRequiredOffsetDateTime(node, "startTime", OFFSET_DATE_TIME_FORMATTER);
        OffsetDateTime endDateTime = asRequiredOffsetDateTime(node, "endTime", OFFSET_DATE_TIME_FORMATTER);

        return new TimeFrame(ofStartDateTimeAndEndDateTime(startDateTime, endDateTime));
{'fraction_non_alphanumeric': 0.07967313585291114, 'fraction_numerical': 0.003268641470888662, 'mean_word_length': 5.066914498141264, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '7593952', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1343, 'n_words': 377}