Ejemplo n.º 1
0
////// Funnels.
weather_sum sum_conditions( const time_point &start, const time_point &end,
                            const tripoint &location )
{
    time_duration tick_size = 0_turns;
    weather_sum data;

    const auto wgen = g->get_cur_weather_gen();
    for( time_point t = start; t < end; t += tick_size ) {
        const time_duration diff = end - t;
        if( diff < 10_turns ) {
            tick_size = 1_turns;
        } else if( diff > 7_days ) {
            tick_size = 1_hours;
        } else {
            tick_size = 1_minutes;
        }

        weather_type wtype;
        if( g->weather_override == WEATHER_NULL ) {
            wtype = wgen.get_weather_conditions( location, t, g->get_seed() );
        } else {
            wtype = g->weather_override;
        }
        proc_weather_sum( wtype, data, t, tick_size );
        w_point w = wgen.get_weather( location, t, g->get_seed() );
        data.wind_amount += get_local_windpower( g->windspeed, overmap_buffer.ter( location ), location,
                            g->winddirection, false ) * to_turns<int>( tick_size );
    }
    return data;
}
Ejemplo n.º 2
0
weather_type weather_generator::get_weather_conditions(const point &location, const calendar &t) const
{
    w_point w(get_weather(location, t));
    weather_type wt = get_weather_conditions(w);
    // Make sure we don't say it's sunny at night! =P
    if (wt == WEATHER_SUNNY && t.is_night()) { return WEATHER_CLEAR; }
    return wt;
}
Ejemplo n.º 3
0
static void run_weather() {
	enum Joystick_dir curJoy = getJoyDirection();
	switch (curJoy) {
	case RIGHT:
		get_weather(B_WEATHER_CURR);
		print_weather("Current Weather\n", "^ Forecast");
		break;
	case LEFT:
		get_weather(B_WEATHER_FOR);
		print_weather("Forecast\n", "v Current Weather");
		break;
	case IN:
		next_state = MAIN_WATCH;
		break;
	default:
		break;
	}
}
Ejemplo n.º 4
0
weather_type weather_generator::get_weather_conditions( const tripoint &location,
        const time_point &t, unsigned seed ) const
{
    w_point w( get_weather( location, t, seed ) );
    weather_type wt = get_weather_conditions( w );
    // Make sure we don't say it's sunny at night! =P
    if( wt == WEATHER_SUNNY && calendar( to_turn<int>( t ) ).is_night() ) {
        return WEATHER_CLEAR;
    }
    return wt;
}
Ejemplo n.º 5
0
void weather_generator::test_weather() const
{
    // Outputs a Cata year's worth of weather data to a csv file.
    // Usage:
    // weather_generator WEATHERGEN(0); // Seeds the weather object.
    // WEATHERGEN.test_weather(); // Runs this test.
    std::ofstream testfile;
    testfile.open("weather.output", std::ofstream::trunc);
    testfile << "turn,temperature(F),humidity(%),pressure(mB)" << std::endl;

    for (calendar i(calendar::turn); i.get_turn() < calendar::turn + 14400 * 2 * calendar::turn.year_length(); i+=200) {
        w_point w = get_weather(point(0, 0), i);
        testfile << i.get_turn() << "," << w.temperature << "," << w.humidity << "," << w.pressure << std::endl;
    }
    //debugmsg("Starting season: %s", ACTIVE_WORLD_OPTIONS["INITIAL_SEASON"].getValue().c_str());
}
Ejemplo n.º 6
0
void weather_generator::test_weather() const
{
    // Outputs a Cata year's worth of weather data to a csv file.
    // Usage:
    // weather_generator WEATHERGEN(0); // Seeds the weather object.
    // WEATHERGEN.test_weather(); // Runs this test.
    std::ofstream testfile;
    testfile.open( "weather.output", std::ofstream::trunc );
    testfile << "turn,temperature(F),humidity(%),pressure(mB)" << std::endl;

    for( calendar i( calendar::turn );
         i.get_turn() < calendar::turn + 14400 * 2 * calendar::turn.year_length(); i += 200 ) {
        w_point w = get_weather( point( 0, 0 ), i );
        testfile << i.get_turn() << "," << w.temperature << "," << w.humidity << "," << w.pressure <<
                 std::endl;
    }
}
Ejemplo n.º 7
0
void weather_generator::test_weather() const
{
    // Outputs a Cata year's worth of weather data to a CSV file.
    // Usage:
    //@todo: this is wrong. weather_generator does not have such a constructor
    // weather_generator WEATHERGEN(0); // Seeds the weather object.
    // WEATHERGEN.test_weather(); // Runs this test.
    std::ofstream testfile;
    testfile.open( "weather.output", std::ofstream::trunc );
    testfile << "turn,temperature(F),humidity(%),pressure(mB)" << std::endl;

    const time_point begin = calendar::turn;
    const time_point end = begin + 2 * calendar::year_length();
    for( time_point i = begin; i < end; i += 200_turns ) {
        //@todo: a new random value for each call to get_weather? Is this really intended?
        w_point w = get_weather( tripoint_zero, to_turn<int>( i ), rand() );
        testfile << to_turn<int>( i ) << "," << w.temperature << "," << w.humidity << "," << w.pressure <<
                 std::endl;
    }
}
Ejemplo n.º 8
0
// Make weather show something....
string get_extra_long()
{
    string	weather_str;
    string	other_extra_long;

    weather_str = get_weather();
    if (!weather_str || !strlen(weather_str))
    {
	return ::get_extra_long();
    }
    else
    {
	other_extra_long = ::get_extra_long();
	if (!other_extra_long)
	{
	    return weather_str;
	}
	else
	{
	    return other_extra_long + weather_str + "\n";
	}
    }
}
Ejemplo n.º 9
0
/**
 * Generate textual weather forecast for the specified radio tower.
 */
std::string weather_forecast( const point &abs_sm_pos )
{
    std::ostringstream weather_report;
    // Local conditions
    const auto cref = overmap_buffer.closest_city( tripoint( abs_sm_pos, 0 ) );
    const std::string city_name = cref ? cref.city->name : std::string( _( "middle of nowhere" ) );
    // Current time
    weather_report << string_format(
                       _( "The current time is %s Eastern Standard Time.  At %s in %s, it was %s. The temperature was %s. " ),
                       to_string_time_of_day( calendar::turn ), print_time_just_hour( calendar::turn ),
                       city_name,
                       weather_data( g->weather ).name, print_temperature( g->temperature )
                   );

    //weather_report << ", the dewpoint ???, and the relative humidity ???.  ";
    //weather_report << "The wind was <direction> at ? mi/km an hour.  ";
    //weather_report << "The pressure was ??? in/mm and steady/rising/falling.";

    // Regional conditions (simulated by choosing a random range containing the current conditions).
    // Adjusted for weather volatility based on how many weather changes are coming up.
    //weather_report << "Across <region>, skies ranged from <cloudiest> to <clearest>.  ";
    // TODO: Add fake reports for nearby cities

    // TODO: weather forecast
    // forecasting periods are divided into 12-hour periods, day (6-18) and night (19-5)
    // Accumulate percentages for each period of various weather statistics, and report that
    // (with fuzz) as the weather chances.
    // int weather_proportions[NUM_WEATHER_TYPES] = {0};
    double high = -100.0;
    double low = 100.0;
    const tripoint abs_ms_pos = tripoint( sm_to_ms_copy( abs_sm_pos ), 0 );
    // TODO: wind direction and speed
    const time_point last_hour = calendar::turn - ( calendar::turn - calendar::time_of_cataclysm ) %
                                 1_hours;
    for( int d = 0; d < 6; d++ ) {
        weather_type forecast = WEATHER_NULL;
        const auto wgen = g->get_cur_weather_gen();
        for( time_point i = last_hour + d * 12_hours; i < last_hour + ( d + 1 ) * 12_hours; i += 1_hours ) {
            w_point w = wgen.get_weather( abs_ms_pos, i, g->get_seed() );
            forecast = std::max( forecast, wgen.get_weather_conditions( w ) );
            high = std::max( high, w.temperature );
            low = std::min( low, w.temperature );
        }
        std::string day;
        bool started_at_night;
        const time_point c = last_hour + 12_hours * d;
        if( d == 0 && calendar( to_turn<int>( c ) ).is_night() ) {
            day = _( "Tonight" );
            started_at_night = true;
        } else {
            day = _( "Today" );
            started_at_night = false;
        }
        if( d > 0 && ( ( started_at_night && !( d % 2 ) ) || ( !started_at_night && d % 2 ) ) ) {
            day = string_format( pgettext( "Mon Night", "%s Night" ), to_string( day_of_week( c ) ) );
        } else {
            day = to_string( day_of_week( c ) );
        }
        weather_report << string_format(
                           _( "%s... %s. Highs of %s. Lows of %s. " ),
                           day, weather_data( forecast ).name,
                           print_temperature( high ), print_temperature( low )
                       );
    }
    return weather_report.str();
}
Ejemplo n.º 10
0
w_point weather_generator::get_weather(const tripoint &location, const calendar &t) const
{
    return get_weather( point( location.x, location.y ), t );
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
    int sockfd, numbytes;  
    char buf[MAXDATASIZE];
    char version[50];
    hilow_parse hilow;
    loop_parse loop;// __attribute__ ((packed));
    struct addrinfo hints, *servinfo, *p;
    int rv;
    char s[INET6_ADDRSTRLEN];

    if (argc != 2) {
        fprintf(stderr,"usage: client hostname\n");
        exit(1);
    }

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    if ((rv = getaddrinfo(argv[1], PORT, &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }

    // loop through all the results and connect to the first we can
    for(p = servinfo; p != NULL; p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype,
                p->ai_protocol)) == -1) {
            perror("client: socket");
            continue;
        }

        if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
            close(sockfd);
            perror("client: connect");
            continue;
        }

        break;
    }

    if (p == NULL) {
        fprintf(stderr, "client: failed to connect\n");
        return 2;
    }

    inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
            s, sizeof s);
    //printf("client: connecting to %s\n", s);

    freeaddrinfo(servinfo); // all done with this structure


/***	HILOWS	***/
    buffer data = get_weather("HILOWS",sockfd);
    find_start(&data);
    memcpy(&hilow,data.data,data.len);
    printf("daily high wind speed = %umph\n", hilow.wind.day);
    printf("daily high temperature = %.2f F\n",((float)hilow.outTemp.dayHigh/10));
    printf("daily low DP = %d F\n",hilow.dewPoint.dayLow);
    printf("mothly high Humididty = %u%%\n", hilow.extraHums.monthHigh[0]);
    printf("daily Low Humidity = %u%%\n", hilow.extraHums.dayLow[0]);
    data = get_weather("LOOP 1",sockfd);
    find_start(&data);
    memcpy(&loop,data.data,data.len);
    //printInHex(data.data,data.len);printf("\n");

//    printf("id\t\t\t= %c%c%c\n",loop.id[0], loop.id[1], loop.id[2]);
//    printf("barTrend\t\t= %u\n", loop.barTrend);
//    printf("Packet type\t\t= %u\n",(loop.packetType));
//    printf("NextRecord\t\t= %u\n",loop.nextRecord);
    printf("barometric pressure\t= %.3f in. Hg\n",(float)loop.barometer/1000);
//    printf("Inside Temperature\t= %.2f F %.2f C\n",((float)loop.insideTemperature/10), F2C((float)loop.insideTemperature/10));
//    printf("Inside Humidity\t\t= %d%%\n",loop.insideHumidity);
    printf("Outside Temperature\t= %.2f F %.2f C\n", ((float)loop.outsideTemperature/10),F2C((float)loop.outsideTemperature/10));
    printf("Wind Speed\t\t= %u mph\n", loop.windSpeed);
    printf("10 Min Avg Wind Speed\t= %d mph\n",loop.tenMinAvgWS);
    printf("Wind Direction\t\t= %u degrees\n", loop.windDirection);
    printf("outside Humidity \t= %d%%\n",loop.outsideHumidity);
    printf("Rain Rate\t\t= %.2f in. per hour\n",((float)loop.rainRate/100));
    printf("Solar Radiation\t\t= %u watts/m^2\n",loop.solarRadiation);
    printf("Day Rain \t\t= %.2f in.\n",((float)loop.dayRain/100)); 
    printf("Month Rain \t\t= %.2f in.\n",((float)loop.monthRain/100)); 
    printf("Year Rain \t\t= %.2f in.\n",((float)loop.yearRain/100)); 
    printf("Day ET \t\t\t= %.2f in.\n",((float)loop.dayET/100)); 
    printf("Month ET \t\t= %.2f in.\n",((float)loop.monthET/100)); 
    printf("Year ET \t\t= %.2f in.\n",((float)loop.yearET/100)); 
    printf("sunrise was at \t\t  %d:%.2d\n", loop.timeOfSunrise/100, loop.timeOfSunrise %100);
    printf("sunset was at \t\t  %d:%.2d\n",loop.timeOfSunset/100,loop.timeOfSunset %100);
    close(sockfd);

    return 0;
}
Ejemplo n.º 12
0
static void start_weather() {
	get_weather(B_WEATHER_CURR);
	print_weather("Current Weather\n", "^ Forecast");
}
Ejemplo n.º 13
0
void forecast_update() {
    if(needs_refresh || current_time.minutes % UPDATE_INTERVAL == 0) {
        needs_refresh = false;
        get_weather();
    }
}
Ejemplo n.º 14
0
// Redraw time when it's changed (every second)
void handle_timechanges(struct tm *tick_time, TimeUnits units_changed){
  // TimeUnits to redraw just part of screen
  // Buffer where we write time
  static char time_buffer[17];
  
  if (militaryTime) {
    strftime(time_buffer, sizeof(time_buffer), "%H:%M:%S %d.%m %w", tick_time);
  } else {
    strftime(time_buffer, sizeof(time_buffer), "%I:%M:%S %d.%m %w", tick_time);
  }
  
  // Separate digits
  static char hours_1st_digit[2];
  hours_1st_digit[0] = time_buffer[0];
  hours_1st_digit[1] = '\0';
  
  static char hours_2nd_digit[2];
  hours_2nd_digit[0] = time_buffer[1];
  hours_2nd_digit[1] = '\0';
  
  static char minutes_1st_digit[2];
  minutes_1st_digit[0] = time_buffer[3];
  minutes_1st_digit[1] = '\0';
  
  static char minutes_2nd_digit[2];
  minutes_2nd_digit[0] = time_buffer[4];
  minutes_2nd_digit[1] = '\0';
  
  static char seconds_1st_digit[2];
  seconds_1st_digit[0] = time_buffer[6];
  //seconds_1st_digit[0] = '8'; // debug line
  seconds_1st_digit[1] = '\0';
  
  static char seconds_2nd_digit[2];
  seconds_2nd_digit[0] = time_buffer[7];
  //seconds_2nd_digit[0] = '8';
  seconds_2nd_digit[1] = '\0';
  
  static char day_1st_digit[2];
  day_1st_digit[0] = time_buffer[9];
  //day_1st_digit[0] = '0';
  day_1st_digit[1] = '\0';
  
  static char day_2nd_digit[2];
  day_2nd_digit[0] = time_buffer[10];
  //day_2nd_digit[0] = '0';
  day_2nd_digit[1] = '\0';
  
  static char date_delimiter[2];
  date_delimiter[0] = '/';
  date_delimiter[1] = '\0';
  
  static char month_1st_digit[2];
  month_1st_digit[0] = time_buffer[12];
  //month_1st_digit[0] = '0';
  month_1st_digit[1] = '\0';
  
  static char month_2nd_digit[2];
  month_2nd_digit[0] = time_buffer[13];
  //month_2nd_digit[0] = '8';
  month_2nd_digit[1] = '\0';
  
  static char day_of_week_id[2];
  day_of_week_id[0] = time_buffer[15];
  static char day_of_week[3];
    
  switch (day_of_week_id[0]){
    case '0':
    {
      strcpy(day_of_week, "SU");
      break;
    }
    case '1':
    {
      strcpy(day_of_week, "MO");
      break;
    }
    case '2':
    {
      strcpy(day_of_week, "TU");
      break;
    }
    case '3':
    {
      strcpy(day_of_week, "WE");
      break;
    }
    case '4':
    {
      strcpy(day_of_week, "TH");
      break;
    }
    case '5':
    {
      strcpy(day_of_week, "FR");
      break;
    }
    case '6':
    {
      strcpy(day_of_week, "SA");
      break;
    }
    default:
     strcpy(day_of_week, "NA");    
  }
  
  // Draw time
  text_layer_set_text(hours_1st_layer, hours_1st_digit);
  text_layer_set_text(hours_2nd_layer, hours_2nd_digit);
  text_layer_set_text(minutes_1st_layer, minutes_1st_digit);
  text_layer_set_text(minutes_2nd_layer, minutes_2nd_digit);
  text_layer_set_text(seconds_1st_layer, seconds_1st_digit);
  text_layer_set_text(seconds_2nd_layer, seconds_2nd_digit);
  
  // Drawing date according format.
  if (dateDDMM){
    text_layer_set_text(date_1st_layer, day_1st_digit);
    text_layer_set_text(date_2nd_layer, day_2nd_digit);
    text_layer_set_text(date_3rd_layer, month_1st_digit);
    text_layer_set_text(date_4th_layer, month_2nd_digit);
  } else {
    text_layer_set_text(date_1st_layer, month_1st_digit);
    text_layer_set_text(date_2nd_layer, month_2nd_digit);
    text_layer_set_text(date_3rd_layer, day_1st_digit);
    text_layer_set_text(date_4th_layer, day_2nd_digit);
  }

  text_layer_set_text(date_delimiter_layer, date_delimiter);
  text_layer_set_text(day_of_week_layer, day_of_week);
  
  // Get weather update
  if (weatherCountdown > 0) {
    weatherCountdown -= 1;
  } else {
    get_weather();
    weatherCountdown = weatherCountdownInit;
  }
  
  // Draw battery state
  static char battery_buffer[5];
  snprintf(battery_buffer, sizeof(battery_buffer), "%02d%%", s_battery_level);
  text_layer_set_text(s_battery_info_layer, battery_buffer);
}
Ejemplo n.º 15
0
// Callback for receiving messages from AppMessage API
static void inbox_received_callback(DictionaryIterator *iterator, void *context){
  static char temperature_buffer[8];
  static char conditions_buffer[32];
  static char weather_layer_buffer[32];
  
  // Read first item
  Tuple *t = dict_read_first(iterator);
  
  // For all items
  while(t != NULL){
    // Define which key was received
    switch(t->key){
      case KEY_TEMPERATURE:
        if (tempC){
          snprintf(temperature_buffer, sizeof(temperature_buffer), "%dC", (int)t->value->int32);
        } else {
          int tempF = (int)t->value->int32 * 1.8 + 32;
          snprintf(temperature_buffer, sizeof(temperature_buffer), "%dF", tempF);
        }
        
        break;
      case KEY_CONDITIONS:
        snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", t->value->cstring);
        break;
      case KEY_ERROR:
        snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", t->value->cstring);
        break;
      case KEY_MILITARY_TIME:
        if (t->value->int8 == 102 || t->value->int8 == 0){
          militaryTime = false;
          
        } else {
          militaryTime = true;
        }
      
        persist_write_bool(KEY_MILITARY_TIME, militaryTime);
        break;
      case KEY_TEMPC:
        if (t->value->int8 == 102 || t->value->int8 == 0){
          tempC = false;
          
        } else {
          tempC = true;
        }

        get_weather(); // Reread weather
        persist_write_bool(KEY_TEMPC, tempC);
        break;
      case KEY_DATEDDMM:
        if (t->value->int8 == 102 || t->value->int8 == 0){
          dateDDMM = false;
          
        } else {
          dateDDMM = true;
        }
        APP_LOG(APP_LOG_LEVEL_ERROR, "Date format %d", (int)t->key);
      
        persist_write_bool(KEY_DATEDDMM, dateDDMM);
        break;
      default:
        APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int)t->key);
    }

    t = dict_read_next(iterator);
  }
  
  snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), 
           "%s %s", temperature_buffer, conditions_buffer);
  text_layer_set_text(s_weather_layer, weather_layer_buffer);
}