Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <market/bootcamp/deep_dive/goncharovea7/ProtoFirst/Proto/pro.pb.h>
- #include <mapreduce/yt/interface/client.h>
- #include <library/getopt/last_getopt.h>
- #include <iostream>
- #include <fstream>
- #include <regex>
- #include <algorithm>
- #include <stdio.h>
- using namespace NYT;
- int get_min(int a, int b) {
- return a > b ? b : a;
- }
- int get_max(int a, int b) {
- return a > b ? a : b;
- }
- struct Values {
- int max, min, avr, sum, cnt;
- Values() {
- max = -1e9;
- min = 1e9;
- avr = 0;
- sum = 0;
- cnt = 0;
- }
- void reAvr(int dsum) {
- sum += dsum;
- ++cnt;
- avr = sum / cnt;
- }
- void reMin(int newVal) {
- min = get_min(min, newVal);
- }
- void reMax(int newVal) {
- max = get_max(max, newVal);
- }
- ~Values();
- }
- int main(int argc, char** argv) {
- TString inputFilePath;
- NLastGetopt::TOpts opts;
- opts.AddLongOption("input", "Protobuf file path")
- .StoreResult(&inputFilePath)
- .Required();
- NLastGetopt::TOptsParseResult(&opts, argc, argv);
- TTable table;
- std::fstream input(inputFilePath, std::ios::in | std::ios::binary);
- table.ParseFromIstream(&input);
- THashMap<uint64_t, Values> categor_info;
- THashMap<int64_t, Values> model_info;
- for(i = 0; i < table.info_size(); ++i) {
- const Tinfo& info = table.info(i);
- categor_info[info.category_id()] = Values();
- categor_info[info.category_id()].reAvr((int)info.click_price());
- categor_info[info.category_id()].reMin((int)info.click_price());
- categor_info[info.category_id()].reMax((int)info.click_price());
- model_info[info.hyper_id()] = Values();
- model_info[info.hyper_id()].reAvr((int)info.click_price());
- model_info[info.hyper_id()].reMin((int)info.click_price());
- model_info[info.hyper_id()].reMax((int)info.click_price());
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement