コード例 #1
0
void SplitterInputReader::MoveToNextTrainSession() {
    while (in.HasNextSession()) {
        ++num_sessions_total;
        Session* s = in.GetNextSession();
        if (!valid_users.count(s->user_id)) {
            ++num_sessions_skipped;
            // Invalid user. Skipping.
            continue;
        }
        int day_id = s->day_id ;
        assert(day_id > 0 && day_id <= DAYS_UNDER_OBSERVATION);
        if (is_in_train[day_id - 1]) {
            next_session = s;
            return;
        } else {
            test_data_writer.Print(*s);
            if (s->HasSwitches()) {
                expected_sessions_with_switches.push_back(s->session_id);
            }
            delete s;
        }
    }
    next_session = NULL;
    // End of sessions
    test_data_writer.Close();
}
コード例 #2
0
void SplitterInputReader::PrepareMetadata(const MarkedData &data) const {
    //map<int, set<int> > users_to_sessions; // maps user_id to set of all days where any sessions are found
    map<int, set<int> > users_to_sessions_with_switches; // same but only sessions with switches are counted
    set<int> user_ids;
    PlainInputReader temp_input(data);
    while (temp_input.HasNextSession()) {
        Session* s = temp_input.GetNextSession();
        user_ids.insert(s->user_id);
    //    users_to_sessions[s->user_id].insert(s->day_id);
        if (s->HasSwitches()) {
            users_to_sessions_with_switches[s->user_id].insert(s->day_id);
        }
        delete s;
    }
    FILE* out_file = fopen(GetMetadataFileName(data).c_str(), "wb");
    fprintf(out_file, "%d\n", (int)user_ids.size());
    for (set<int>::iterator it = user_ids.begin(); it != user_ids.end(); ++it) {
        int user_id = *it;
        fprintf(out_file, "%d", user_id);
        set<int> days;
        /*
        days = users_to_sessions[user_id];
        fprintf(out_file, " %d", (int)days.size());
        for (set<int>::iterator it2 = days.begin(); it2 != days.end(); ++it2) {
            fprintf(out_file, " %d", *it2);
        }
         */
        
        days = users_to_sessions_with_switches[user_id];
        fprintf(out_file, " %d", (int)days.size());
        for (set<int>::iterator it2 = days.begin(); it2 != days.end(); ++it2) {
            fprintf(out_file, " %d", *it2);
        }
        fprintf(out_file, "\n");
    }
    fclose(out_file);
    
}