Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <market/bootcamp/deep_dive/goncharovea7/ProtoFirst/Proto/pro.pb.h>
  2.  
  3. #include <mapreduce/yt/interface/client.h>
  4. #include <library/getopt/last_getopt.h>
  5.  
  6. #include <iostream>
  7. #include <fstream>
  8. #include <regex>
  9. #include <algorithm>
  10. #include <stdio.h>
  11.  
  12. using namespace NYT;
  13.  
  14. int get_min(int a, int b) {
  15. return a > b ? b : a;
  16. }
  17.  
  18. int get_max(int a, int b) {
  19. return a > b ? a : b;
  20. }
  21.  
  22. struct Values {
  23. int max, min, avr, sum, cnt;
  24. Values() {
  25. max = -1e9;
  26. min = 1e9;
  27. avr = 0;
  28. sum = 0;
  29. cnt = 0;
  30. }
  31.  
  32. void reAvr(int dsum) {
  33. sum += dsum;
  34. ++cnt;
  35. avr = sum / cnt;
  36. }
  37.  
  38. void reMin(int newVal) {
  39. min = get_min(min, newVal);
  40. }
  41.  
  42. void reMax(int newVal) {
  43. max = get_max(max, newVal);
  44. }
  45.  
  46. ~Values();
  47. }
  48.  
  49. int main(int argc, char** argv) {
  50. TString inputFilePath;
  51. NLastGetopt::TOpts opts;
  52. opts.AddLongOption("input", "Protobuf file path")
  53. .StoreResult(&inputFilePath)
  54. .Required();
  55. NLastGetopt::TOptsParseResult(&opts, argc, argv);
  56. TTable table;
  57. std::fstream input(inputFilePath, std::ios::in | std::ios::binary);
  58. table.ParseFromIstream(&input);
  59.  
  60. THashMap<uint64_t, Values> categor_info;
  61. THashMap<int64_t, Values> model_info;
  62.  
  63. for(i = 0; i < table.info_size(); ++i) {
  64. const Tinfo& info = table.info(i);
  65. categor_info[info.category_id()] = Values();
  66. categor_info[info.category_id()].reAvr((int)info.click_price());
  67. categor_info[info.category_id()].reMin((int)info.click_price());
  68. categor_info[info.category_id()].reMax((int)info.click_price());
  69.  
  70. model_info[info.hyper_id()] = Values();
  71. model_info[info.hyper_id()].reAvr((int)info.click_price());
  72. model_info[info.hyper_id()].reMin((int)info.click_price());
  73. model_info[info.hyper_id()].reMax((int)info.click_price());
  74. }
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement