Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. use rand::Rng;
  2. use rand::distributions::Distribution;
  3. use rand::seq::SliceRandom;
  4.  
  5. const ZIP_CODES: &[&str] = &[
  6. "79936",
  7. "90011",
  8. "60629",
  9. "90650",
  10. "90201",
  11. "77084",
  12. "92335",
  13. "78521",
  14. "77449",
  15. "78572",
  16. "90250",
  17. "90280",
  18. "11226",
  19. "90805",
  20. "91331",
  21. "08701",
  22. "90044",
  23. "92336",
  24. "00926",
  25. "94565",
  26. ];
  27.  
  28. const MEANS: &[f64] = &[
  29. 242.53,
  30. 70.55,
  31. 153.54,
  32. 530.51,
  33. 756.82,
  34. 868.62,
  35. 342.91,
  36. 715.51,
  37. 118.13,
  38. 467.10,
  39. 266.31,
  40. 50.50,
  41. 976.94,
  42. 734.34,
  43. 873.61,
  44. 618.70,
  45. 12.98,
  46. 845.99,
  47. 168.96,
  48. 459.14,
  49. ];
  50.  
  51. const CONVERSION_RATES: &[f64] = &[
  52. 0.76,
  53. 0.72,
  54. 0.78,
  55. 0.82,
  56. 0.85,
  57. 0.65,
  58. 0.88,
  59. 0.55,
  60. 0.20,
  61. 0.37,
  62. 0.86,
  63. 0.35,
  64. 0.94,
  65. 0.35,
  66. 0.79,
  67. 0.41,
  68. 0.53,
  69. 0.63,
  70. 0.87,
  71. 0.33,
  72. ];
  73.  
  74.  
  75. fn main() {
  76. let mut rng = rand::thread_rng();
  77. let mut samples = Vec::new();
  78. for (zip, (conversion_rate, mean)) in ZIP_CODES.iter().copied().zip(CONVERSION_RATES.iter().copied().zip(MEANS.iter().copied())) {
  79. let normal = rand::distributions::Normal::new(mean, 50.0);
  80. for _ in 0..rng.gen_range(50, 150) {
  81. if rng.gen_bool(conversion_rate) {
  82. samples.push(format!("('{}', {:.2}),", zip, normal.sample(&mut rng).max(0.0)));
  83. } else {
  84. samples.push(format!("('{}', 0.0),", zip));
  85. }
  86. }
  87. }
  88.  
  89. samples.shuffle(&mut rng);
  90.  
  91. eprintln!("INSERT INTO sessions (zip_code, sale_amount) VALUES");
  92. for sample in samples {
  93. eprintln!("{}", sample);
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement