<commit_before>import { OsType } from './../../../shared/models/arm/stacks';
import { Observable } from 'rxjs/Observable';
import { LogService } from 'app/shared/services/log.service';
import { TranslateService } from '@ngx-translate/core';
import { PortalResources } from 'app/shared/models/portal-resources';
import { SpecPickerComponent } from './../spec-picker.component';
import {
  SpecCostQueryResult,
  SpecResourceSet,
  SpecCostQueryResultStatusCode,
  SpecCostQueryResultSpecStatusCode,
} from './../price-spec-manager/billing-models';
import {
  PriceSpecGroup,
  PriceSpecGroupType,
  DevSpecGroup,
  ProdSpecGroup,
  IsolatedSpecGroup,
  BannerMessage,
  BannerMessageLevel,
  GenericSpecGroup,
  SpecGroup,
} from './price-spec-group';
import { PortalService } from './../../../shared/services/portal.service';
import { PlanService } from './../../../shared/services/plan.service';
import { Injector, Injectable } from '@angular/core';
import { ArmSubcriptionDescriptor, ArmResourceDescriptor } from '../../../shared/resourceDescriptors';
import { ResourceId, ArmObj } from '../../../shared/models/arm/arm-obj';
import { ServerFarm } from '../../../shared/models/server-farm';
import { SpecCostQueryInput } from './billing-models';
import { PriceSpecInput, PriceSpec } from './price-spec';
import { Subject } from 'rxjs/Subject';
import { BillingMeter } from '../../../shared/models/arm/billingMeter';
import { LogCategories, Links, ScenarioIds } from '../../../shared/models/constants';
import { Tier } from './../../../shared/models/serverFarmSku';
import { AuthzService } from 'app/shared/services/authz.service';
import { AppKind } from 'app/shared/Utilities/app-kind';
import { BillingService } from 'app/shared/services/billing.service';
import { ScenarioService } from 'app/shared/services/scenario/scenario.service';

export interface SpecPickerInput<T> {
  id: ResourceId;
  data?: T;
  specPicker: SpecPickerComponent;
}

export interface PlanSpecPickerData {
  subscriptionId: string;
  location: string;
  hostingEnvironmentName: string | null;
  allowAseV2Creation: boolean;
  forbiddenSkus: string[];
  isFunctionApp?: boolean;
  isLinux: boolean;
  isXenon: boolean;
  selectedLegacySkuName: string; // Looks like "small_standard"
  selectedSkuCode?: string; // Can be set in update scenario for initial spec selection
}

export type ApplyButtonState = 'enabled' | 'disabled';

@Injectable()
export class PlanPriceSpecManager {
  private readonly DynamicSku = 'Y1';

  selectedSpecGroup: PriceSpecGroup;
  specGroups: PriceSpecGroup[] = [];

  get currentSkuCode(): string {
    if (!this._plan) {
      return null;
    }

    return this._plan.sku.name;
  }

  private _specPicker: SpecPickerComponent;
  private _plan: ArmObj<ServerFarm>;
  private _subscriptionId: string;
  private _inputs: SpecPickerInput<PlanSpecPickerData>;
  private _ngUnsubscribe$ = new Subject();

  constructor(
    private _authZService: AuthzService,
    private _planService: PlanService,
    private _portalService: PortalService,
    private _ts: TranslateService,
    private _logService: LogService,
    private _injector: Injector,
    private _scenarioService: ScenarioService,
    private _billingService: BillingService
  ) {}

  resetGroups() {
    this.specGroups = [
      new DevSpecGroup(this._injector, this),
      new ProdSpecGroup(this._injector, this),
      new IsolatedSpecGroup(this._injector, this),
    ];
  }

  initialize(inputs: SpecPickerInput<PlanSpecPickerData>) {
    this._specPicker = inputs.specPicker;
    this._inputs = inputs;
    this._subscriptionId = new ArmSubcriptionDescriptor(inputs.id).subscriptionId;

    let pricingTiers = Observable.of(null);
    if (this._scenarioService.checkScenario(ScenarioIds.pricingTierApiEnabled).status === 'enabled') {
      pricingTiers = this._billingService.getPricingTiers(this._subscriptionId);
    }

    this.selectedSpecGroup = this.specGroups[0];
    let specInitCalls: Observable<void>[] = [];

    return Observable.zip(this._getPlan(inputs), pricingTiers, (plan, pt) => ({
      plan: plan,
      pricingTiers: pt,
    })).flatMap(r => {
      // plan is null for new plans
      this._plan = r.plan;

      if (r.pricingTiers) {
        this.specGroups = [
          new GenericSpecGroup(this._injector, this, SpecGroup.Development, r.pricingTiers),
          new GenericSpecGroup(this._injector, this, SpecGroup.Production, r.pricingTiers),
          new GenericSpecGroup(this._injector, this, SpecGroup.Isolated, r.pricingTiers),
        ];
      }
      // Initialize every spec for each spec group.  For most cards this is a no-op, but
      // some require special handling so that we know if we need to hide/disable a card.
      this.specGroups.forEach(g => {
        const priceSpecInput: PriceSpecInput = {
          specPickerInput: inputs,
          plan: this._plan,
          subscriptionId: this._subscriptionId,
        };

        g.initialize(priceSpecInput);
        specInitCalls = specInitCalls.concat(g.recommendedSpecs.map(s => s.initialize(priceSpecInput)));
        specInitCalls = specInitCalls.concat(g.additionalSpecs.map(s => s.initialize(priceSpecInput)));
      });

      return specInitCalls.length > 0 ? Observable.zip(...specInitCalls) : Observable.of(null);
    });
  }

  getSpecCosts() {<commit_msg>Hide isolated spec group for onprem (#3619)<commit_after>import { OsType } from './../../../shared/models/arm/stacks';
import { Observable } from 'rxjs/Observable';
import { LogService } from 'app/shared/services/log.service';
import { TranslateService } from '@ngx-translate/core';
import { PortalResources } from 'app/shared/models/portal-resources';
import { SpecPickerComponent } from './../spec-picker.component';
import {
  SpecCostQueryResult,
  SpecResourceSet,
  SpecCostQueryResultStatusCode,
  SpecCostQueryResultSpecStatusCode,
} from './../price-spec-manager/billing-models';
import {
  PriceSpecGroup,
  PriceSpecGroupType,
  DevSpecGroup,
  ProdSpecGroup,
  IsolatedSpecGroup,
  BannerMessage,
  BannerMessageLevel,
  GenericSpecGroup,
  SpecGroup,
} from './price-spec-group';
import { PortalService } from './../../../shared/services/portal.service';
import { PlanService } from './../../../shared/services/plan.service';
import { Injector, Injectable } from '@angular/core';
import { ArmSubcriptionDescriptor, ArmResourceDescriptor } from '../../../shared/resourceDescriptors';
import { ResourceId, ArmObj } from '../../../shared/models/arm/arm-obj';
import { ServerFarm } from '../../../shared/models/server-farm';
import { SpecCostQueryInput } from './billing-models';
import { PriceSpecInput, PriceSpec } from './price-spec';
import { Subject } from 'rxjs/Subject';
import { BillingMeter } from '../../../shared/models/arm/billingMeter';
import { LogCategories, Links, ScenarioIds } from '../../../shared/models/constants';
import { Tier } from './../../../shared/models/serverFarmSku';
import { AuthzService } from 'app/shared/services/authz.service';
import { AppKind } from 'app/shared/Utilities/app-kind';
import { BillingService } from 'app/shared/services/billing.service';
import { ScenarioService } from 'app/shared/services/scenario/scenario.service';

export interface SpecPickerInput<T> {
  id: ResourceId;
  data?: T;
  specPicker: SpecPickerComponent;
}

export interface PlanSpecPickerData {
  subscriptionId: string;
  location: string;
  hostingEnvironmentName: string | null;
  allowAseV2Creation: boolean;
  forbiddenSkus: string[];
  isFunctionApp?: boolean;
  isLinux: boolean;
  isXenon: boolean;
  selectedLegacySkuName: string; // Looks like "small_standard"
  selectedSkuCode?: string; // Can be set in update scenario for initial spec selection
}

export type ApplyButtonState = 'enabled' | 'disabled';

@Injectable()
export class PlanPriceSpecManager {
  private readonly DynamicSku = 'Y1';

  selectedSpecGroup: PriceSpecGroup;
  specGroups: PriceSpecGroup[] = [];

  get currentSkuCode(): string {
    if (!this._plan) {
      return null;
    }

    return this._plan.sku.name;
  }

  private _specPicker: SpecPickerComponent;
  private _plan: ArmObj<ServerFarm>;
  private _subscriptionId: string;
  private _inputs: SpecPickerInput<PlanSpecPickerData>;
  private _ngUnsubscribe$ = new Subject();

  constructor(
    private _authZService: AuthzService,
    private _planService: PlanService,
    private _portalService: PortalService,
    private _ts: TranslateService,
    private _logService: LogService,
    private _injector: Injector,
    private _scenarioService: ScenarioService,
    private _billingService: BillingService
  ) {}

  resetGroups() {
    this.specGroups = [
      new DevSpecGroup(this._injector, this),
      new ProdSpecGroup(this._injector, this),
      new IsolatedSpecGroup(this._injector, this),
    ];
  }

  initialize(inputs: SpecPickerInput<PlanSpecPickerData>) {
    this._specPicker = inputs.specPicker;
    this._inputs = inputs;
    this._subscriptionId = new ArmSubcriptionDescriptor(inputs.id).subscriptionId;

    let pricingTiers = Observable.of(null);
    if (this._scenarioService.checkScenario(ScenarioIds.pricingTierApiEnabled).status === 'enabled') {
      pricingTiers = this._billingService.getPricingTiers(this._subscriptionId);
    }

    this.selectedSpecGroup = this.specGroups[0];
    let specInitCalls: Observable<void>[] = [];

    return Observable.zip(this._getPlan(inputs), pricingTiers, (plan, pt) => ({
      plan: plan,
      pricingTiers: pt,
    })).flatMap(r => {
      // plan is null for new plans
      this._plan = r.plan;

      if (r.pricingTiers) {
        this.specGroups = [
          new GenericSpecGroup(this._injector, this, SpecGroup.Development, r.pricingTiers),
          new GenericSpecGroup(this._injector, this, SpecGroup.Production, r.pricingTiers),
        ];
      }
      // Initialize every spec for each spec group.  For most cards this is a no-op, but
      // some require special handling so that we know if we need to hide/disable a card.
      this.specGroups.forEach(g => {
        const priceSpecInput: PriceSpecInput = {
          specPickerInput: inputs,
          plan: this._plan,
          subscriptionId: this._subscriptionId,
        };

        g.initialize(priceSpecInput);
        specInitCalls = specInitCalls.concat(g.recommendedSpecs.map(s => s.initialize(priceSpecInput)));
        specInitCalls = specInitCalls.concat(g.additionalSpecs.map(s => s.initialize(priceSpecInput)));
      });

      return specInitCalls.length > 0 ? Observable.zip(...specInitCalls) : Observable.of(null);
    });
  }

  getSpecCosts() {
{'fraction_non_alphanumeric': 0.1260599208592425, 'fraction_numerical': 0.0011305822498586771, 'mean_word_length': 3.7793786582620443, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2500044', 'n_tokens_mistral': 3143, 'n_tokens_neox': 3134, 'n_words': 697}