public static function generateData($memberProperty, $property, $year, $quarter, $accountId)
 {
     $propertyKey = 'memProperty.' . $memberProperty->_id;
     $keys = ['productId' => true, $propertyKey => true];
     $condition = ['year' => $year, 'quarter' => $quarter, 'accountId' => $accountId];
     $initial = ['avg' => 0, 'codes' => ['count' => 0], 'members' => ['count' => 0]];
     $reduce = 'function(doc, prev) {
         if (!prev.members[doc.memberId]) {
             prev.members[doc.memberId] = true;
             prev.members["count"]++;
         }
         if (!prev.codes[doc.code]) {
             prev.codes[doc.code] = true;
             prev.codes["count"]++;
         }
     }';
     $finalize = 'function(prev) {
         prev.avg = prev.codes["count"] / prev.members["count"];
         delete prev.codes;
         delete prev.members;
     }';
     $statsItems = ModelStatsMemberCampaignLogDaily::getCollection()->group($keys, $initial, $reduce, ['condition' => $condition, 'finalize' => $finalize]);
     foreach ($statsItems as $statsItem) {
         $condition['propId'] = $property;
         $condition['propValue'] = $statsItem[$propertyKey];
         $productId = $statsItem['productId'];
         $condition['productId'] = $productId;
         $stats = ModelStatsMemberPropTradeCodeAvgQuarterly::findOne($condition);
         if (empty($stats)) {
             $stats = new ModelStatsMemberPropTradeCodeAvgQuarterly();
             $product = Product::findByPk($productId);
             $productName = '';
             if (!empty($product)) {
                 $productName = $product->name;
             }
             $stats->propId = $property;
             $stats->propValue = $statsItem[$propertyKey];
             $stats->productId = $productId;
             $stats->productName = $productName;
             $stats->year = $year;
             $stats->quarter = $quarter;
             $stats->accountId = $accountId;
         }
         $stats->avg = $statsItem['avg'];
         $stats->save();
     }
 }