<commit_before>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { submitCondition } from '../../actions/firebase_actions';
import {firebase,firebaseDb} from '../../utils/firebase';
import moment from 'moment';
import {RadioGroup, Radio} from 'react-radio-group';
import Datetime from 'react-datetime';

import 'react-datetime/css/react-datetime.css';

//@ TODO add pull form db if set and two collumns
class SubmitUserSettings extends Component {

  constructor(props) {
      super(props);
      this.onFormSubmit = this.onFormSubmit.bind(this);
      this.state = {
        message: '',
        startDate: Datetime.moment().subtract(18, 'years'), 
        sex: '',
        height: '',
    };
    this.handleDateTimeChange = this.handleDateTimeChange.bind(this);
  }


  handleDateTimeChange(date) {
    this.setState({
      startDate: date
    });
  }
  handleHeightChange(event) {
    this.setState({height: event.target.value});
  }
  componentDidMount(){

    firebaseDb.ref("settings").child(this.props.currentUser.uid).on('value', snap =>{
      var data = snap.val();

       this.setState({
        height: data.height,
        startDate: moment(data.birthday),
        sex: data.sex,
      })

    });

  }
  onFormSubmit(event) {
      event.preventDefault();
      let height = this.state.height;
      let birthday = this.state.startDate.valueOf();
      let sex = this.state.sex;
      console.log("data imput", height, birthday, sex);
      this.setState({message: '',});
      var pefMin =0;
      var pefMid=0;
      function getAge(dateString) {
          var today = new Date();
          var birthDate = new Date(dateString);
          var age = today.getFullYear() - birthDate.getFullYear();
          var m = today.getMonth() - birthDate.getMonth();
          if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
              age--;
          }
          return age;
      }
      function eTo(x){
      return Math.exp(x);
      }
      function ln(i){
      return Math.log(i);
      }

      var age = getAge(birthday);
      if(sex == "male"){
        //pefMin =Math.pow(Math.E, 0.544 * Math.log10(age) - 0.0151 *(age) - 74.7/(height) + 5.48);
        pefMin=  (eTo((0.544 * ln(age)) - (0.0151 * age) - (74.7 / height) + 5.48))*0.5;
        pefMid=  eTo((0.544 * ln(age)) - (0.0151 * age) - (74.7 / height) + 5.48);
      }else{
        pefMid =  eTo((0.376 * ln(age)) - (0.012 * age) - (58.8 / height) + 5.63);
        pefMin = (eTo((0.376 * ln(age)) - (0.012 * age) - (58.8 / height) + 5.63))*0.5;

      } 

      if(height && birthday && sex && this.state.startDate.isBefore(Datetime.moment().subtract(3, 'years'))){
        firebaseDb.ref("settings").child(this.props.currentUser.uid).set({
          height: height,
          birthday: birthday,
          sex: sex,
          pefNorms:{
            min: pefMin,
            mid: pefMid,
          }

        });
        this.setState({
          message: 'Personal settings set',
        });  
      }else{
        this.setState({
          message: 'Please enter height, birthday and sex',
        });        
      }
    
  }

  setSex(value) {
    this.setState({sex: value});
  }

  getValidDate(currentDate, selectedDate){
    console.log("THE CURRENT", current);
    return currentDate.isAfter(  moment() );
  }
    render() {
      return (
      <form id="SubmitConditionData" role="form" onSubmit={this.onFormSubmit}>
        <h4> Your health details </h4>
        <em>For automated condition evaluation</em>
        <h5> {this.state.message} </h5>
        <div className="form-group">
          <label htmlFor="height"> Height </label><commit_msg>FevNorms generation<commit_after>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { submitCondition } from '../../actions/firebase_actions';
import {firebase,firebaseDb} from '../../utils/firebase';
import moment from 'moment';
import {RadioGroup, Radio} from 'react-radio-group';
import Datetime from 'react-datetime';

import 'react-datetime/css/react-datetime.css';

//@ TODO add pull form db if set and two collumns
class SubmitUserSettings extends Component {

  constructor(props) {
      super(props);
      this.onFormSubmit = this.onFormSubmit.bind(this);
      this.state = {
        message: '',
        startDate: Datetime.moment().subtract(18, 'years'), 
        sex: '',
        height: '',
    };
    this.handleDateTimeChange = this.handleDateTimeChange.bind(this);
  }


  handleDateTimeChange(date) {
    this.setState({
      startDate: date
    });
  }
  handleHeightChange(event) {
    this.setState({height: event.target.value});
  }
  componentDidMount(){

    firebaseDb.ref("settings").child(this.props.currentUser.uid).on('value', snap =>{
      var data = snap.val();

       this.setState({
        height: data.height,
        startDate: moment(data.birthday),
        sex: data.sex,
      })

    });

  }
  onFormSubmit(event) {
      event.preventDefault();
      let height = this.state.height;
      let birthday = this.state.startDate.valueOf();
      let sex = this.state.sex;
      console.log("data imput", height, birthday, sex);
      this.setState({message: '',});
      var pefMin=0;
      var pefMid=0;
      var fev1Min=0;
      var fev1Mid=0;
      function getAge(dateString) {
          var today = new Date();
          var birthDate = new Date(dateString);
          var age = today.getFullYear() - birthDate.getFullYear();
          var m = today.getMonth() - birthDate.getMonth();
          if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
              age--;
          }
          return age;
      }
      function eTo(x){
      return Math.exp(x);
      }
      function ln(i){
      return Math.log(i);
      }

      var age = getAge(birthday);
      if(sex == "male"){
        if(age < 20){
          fev1Mid = (-0.7453+height*height*0.00014098+age*-0.04106+age*age*0.004477)*0.8*60;
          fev1Min = (-0.7453+height*height*0.00014098+age*-0.04106+age*age*0.004477)*0.5*60;
        }else{
          fev1Mid=(0.5536+height*height*0.00014098+age*-0.01303+age*age*-0.000172)*0.8*60;
          fev1Min=(0.5536+height*height*0.00014098+age*-0.01303+age*age*-0.000172)*0.5*60;

        }
        //pefMin =Math.pow(Math.E, 0.544 * Math.log10(age) - 0.0151 *(age) - 74.7/(height) + 5.48);
        pefMin=  (eTo((0.544 * ln(age)) - (0.0151 * age) - (74.7 / height) + 5.48))*0.5;
        pefMid=  eTo((0.544 * ln(age)) - (0.0151 * age) - (74.7 / height) + 5.48);
      }else{
        if(age < 18){
          fev1Mid =(-0.871+height*height*0.00011496+age*0.06537)*0.8*60;
          fev1Min =(-0.871+height*height*0.00011496+age*0.06537)*0.5*60;
        }else{
          fev1Mid=(0.4333+height*height*0.00011496+age*-0.00361+age*age*-0.000194)*0.8*60;
          fev1Min=(0.4333+height*height*0.00011496+age*-0.00361+age*age*-0.000194)*0.5*60;
        }
        pefMid =  eTo((0.376 * ln(age)) - (0.012 * age) - (58.8 / height) + 5.63);
        pefMin = (eTo((0.376 * ln(age)) - (0.012 * age) - (58.8 / height) + 5.63))*0.5;

      } 
      console.log("MID FEV1", fev1Mid*60);
      if(height && birthday && sex && this.state.startDate.isBefore(Datetime.moment().subtract(3, 'years'))){
        firebaseDb.ref("settings").child(this.props.currentUser.uid).set({
          height: height,
          birthday: birthday,
          sex: sex,
          pefNorms:{
            min: pefMin,
            mid: pefMid,
          },
          fev1Norms:{
            min: fev1Min,
            mid: fev1Mid,
          },
        });
        this.setState({
          message: 'Personal settings set',
        });  
      }else{
        this.setState({
          message: 'Please enter height, birthday and sex',
        });        
      }

    
  }

  setSex(value) {
    this.setState({sex: value});
  }

  getValidDate(currentDate, selectedDate){
    console.log("THE CURRENT", current);
    return currentDate.isAfter(  moment() );
  }
    render() {
      return (
      <form id="SubmitConditionData" role="form" onSubmit={this.onFormSubmit}>
        <h4> Your health details </h4>
        <em>For automated condition evaluation</em>
        <h5> {this.state.message} </h5>
        <div className="form-group">
          <label htmlFor="height"> Height </label>
{'fraction_non_alphanumeric': 0.16496920890573188, 'fraction_numerical': 0.051515869256276645, 'mean_word_length': 2.2618771726535343, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '818823', 'n_tokens_mistral': 3088, 'n_tokens_neox': 2822, 'n_words': 535}