Best JavaScript code snippet using best
inception_v1.py
Source:inception_v1.py
1# Copyright 2016 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""Contains the definition for inception v1 classification network."""16from __future__ import absolute_import17from __future__ import division18from __future__ import print_function19import tensorflow as tf20from nets import inception_utils21slim = tf.contrib.slim22trunc_normal = lambda stddev: tf.truncated_normal_initializer(0.0, stddev)23def inception_v1_base(inputs,24 final_endpoint='Mixed_5c',25 scope='InceptionV1'):26 """Defines the Inception V1 base architecture.27 This architecture is defined in:28 Going deeper with convolutions29 Christian Szegedy, Wei Liu, Yangqing Jia, Pierre Sermanet, Scott Reed,30 Dragomir Anguelov, Dumitru Erhan, Vincent Vanhoucke, Andrew Rabinovich.31 http://arxiv.org/pdf/1409.4842v1.pdf.32 Args:33 inputs: a tensor of size [batch_size, height, width, channels].34 final_endpoint: specifies the endpoint to construct the network up to. It35 can be one of ['Conv2d_1a_7x7', 'MaxPool_2a_3x3', 'Conv2d_2b_1x1',36 'Conv2d_2c_3x3', 'MaxPool_3a_3x3', 'Mixed_3b', 'Mixed_3c',37 'MaxPool_4a_3x3', 'Mixed_4b', 'Mixed_4c', 'Mixed_4d', 'Mixed_4e',38 'Mixed_4f', 'MaxPool_5a_2x2', 'Mixed_5b', 'Mixed_5c']39 scope: Optional variable_scope.40 Returns:41 A dictionary from components of the network to the corresponding activation.42 Raises:43 ValueError: if final_endpoint is not set to one of the predefined values.44 """45 end_points = {}46 with tf.variable_scope(scope, 'InceptionV1', [inputs]):47 with slim.arg_scope(48 [slim.conv2d, slim.fully_connected],49 weights_initializer=trunc_normal(0.01)):50 with slim.arg_scope([slim.conv2d, slim.max_pool2d],51 stride=1, padding='SAME'):52 end_point = 'Conv2d_1a_7x7'53 net = slim.conv2d(inputs, 64, [7, 7], stride=2, scope=end_point)54 end_points[end_point] = net55 if final_endpoint == end_point: return net, end_points56 end_point = 'MaxPool_2a_3x3'57 net = slim.max_pool2d(net, [3, 3], stride=2, scope=end_point)58 end_points[end_point] = net59 if final_endpoint == end_point: return net, end_points60 end_point = 'Conv2d_2b_1x1'61 net = slim.conv2d(net, 64, [1, 1], scope=end_point)62 end_points[end_point] = net63 if final_endpoint == end_point: return net, end_points64 end_point = 'Conv2d_2c_3x3'65 net = slim.conv2d(net, 192, [3, 3], scope=end_point)66 end_points[end_point] = net67 if final_endpoint == end_point: return net, end_points68 end_point = 'MaxPool_3a_3x3'69 net = slim.max_pool2d(net, [3, 3], stride=2, scope=end_point)70 end_points[end_point] = net71 if final_endpoint == end_point: return net, end_points72 end_point = 'Mixed_3b'73 with tf.variable_scope(end_point):74 with tf.variable_scope('Branch_0'):75 branch_0 = slim.conv2d(net, 64, [1, 1], scope='Conv2d_0a_1x1')76 with tf.variable_scope('Branch_1'):77 branch_1 = slim.conv2d(net, 96, [1, 1], scope='Conv2d_0a_1x1')78 branch_1 = slim.conv2d(branch_1, 128, [3, 3], scope='Conv2d_0b_3x3')79 with tf.variable_scope('Branch_2'):80 branch_2 = slim.conv2d(net, 16, [1, 1], scope='Conv2d_0a_1x1')81 branch_2 = slim.conv2d(branch_2, 32, [3, 3], scope='Conv2d_0b_3x3')82 with tf.variable_scope('Branch_3'):83 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')84 branch_3 = slim.conv2d(branch_3, 32, [1, 1], scope='Conv2d_0b_1x1')85 net = tf.concat(86 axis=3, values=[branch_0, branch_1, branch_2, branch_3])87 end_points[end_point] = net88 if final_endpoint == end_point: return net, end_points89 end_point = 'Mixed_3c'90 with tf.variable_scope(end_point):91 with tf.variable_scope('Branch_0'):92 branch_0 = slim.conv2d(net, 128, [1, 1], scope='Conv2d_0a_1x1')93 with tf.variable_scope('Branch_1'):94 branch_1 = slim.conv2d(net, 128, [1, 1], scope='Conv2d_0a_1x1')95 branch_1 = slim.conv2d(branch_1, 192, [3, 3], scope='Conv2d_0b_3x3')96 with tf.variable_scope('Branch_2'):97 branch_2 = slim.conv2d(net, 32, [1, 1], scope='Conv2d_0a_1x1')98 branch_2 = slim.conv2d(branch_2, 96, [3, 3], scope='Conv2d_0b_3x3')99 with tf.variable_scope('Branch_3'):100 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')101 branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')102 net = tf.concat(103 axis=3, values=[branch_0, branch_1, branch_2, branch_3])104 end_points[end_point] = net105 if final_endpoint == end_point: return net, end_points106 end_point = 'MaxPool_4a_3x3'107 net = slim.max_pool2d(net, [3, 3], stride=2, scope=end_point)108 end_points[end_point] = net109 if final_endpoint == end_point: return net, end_points110 end_point = 'Mixed_4b'111 with tf.variable_scope(end_point):112 with tf.variable_scope('Branch_0'):113 branch_0 = slim.conv2d(net, 192, [1, 1], scope='Conv2d_0a_1x1')114 with tf.variable_scope('Branch_1'):115 branch_1 = slim.conv2d(net, 96, [1, 1], scope='Conv2d_0a_1x1')116 branch_1 = slim.conv2d(branch_1, 208, [3, 3], scope='Conv2d_0b_3x3')117 with tf.variable_scope('Branch_2'):118 branch_2 = slim.conv2d(net, 16, [1, 1], scope='Conv2d_0a_1x1')119 branch_2 = slim.conv2d(branch_2, 48, [3, 3], scope='Conv2d_0b_3x3')120 with tf.variable_scope('Branch_3'):121 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')122 branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')123 net = tf.concat(124 axis=3, values=[branch_0, branch_1, branch_2, branch_3])125 end_points[end_point] = net126 if final_endpoint == end_point: return net, end_points127 end_point = 'Mixed_4c'128 with tf.variable_scope(end_point):129 with tf.variable_scope('Branch_0'):130 branch_0 = slim.conv2d(net, 160, [1, 1], scope='Conv2d_0a_1x1')131 with tf.variable_scope('Branch_1'):132 branch_1 = slim.conv2d(net, 112, [1, 1], scope='Conv2d_0a_1x1')133 branch_1 = slim.conv2d(branch_1, 224, [3, 3], scope='Conv2d_0b_3x3')134 with tf.variable_scope('Branch_2'):135 branch_2 = slim.conv2d(net, 24, [1, 1], scope='Conv2d_0a_1x1')136 branch_2 = slim.conv2d(branch_2, 64, [3, 3], scope='Conv2d_0b_3x3')137 with tf.variable_scope('Branch_3'):138 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')139 branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')140 net = tf.concat(141 axis=3, values=[branch_0, branch_1, branch_2, branch_3])142 end_points[end_point] = net143 if final_endpoint == end_point: return net, end_points144 end_point = 'Mixed_4d'145 with tf.variable_scope(end_point):146 with tf.variable_scope('Branch_0'):147 branch_0 = slim.conv2d(net, 128, [1, 1], scope='Conv2d_0a_1x1')148 with tf.variable_scope('Branch_1'):149 branch_1 = slim.conv2d(net, 128, [1, 1], scope='Conv2d_0a_1x1')150 branch_1 = slim.conv2d(branch_1, 256, [3, 3], scope='Conv2d_0b_3x3')151 with tf.variable_scope('Branch_2'):152 branch_2 = slim.conv2d(net, 24, [1, 1], scope='Conv2d_0a_1x1')153 branch_2 = slim.conv2d(branch_2, 64, [3, 3], scope='Conv2d_0b_3x3')154 with tf.variable_scope('Branch_3'):155 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')156 branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')157 net = tf.concat(158 axis=3, values=[branch_0, branch_1, branch_2, branch_3])159 end_points[end_point] = net160 if final_endpoint == end_point: return net, end_points161 end_point = 'Mixed_4e'162 with tf.variable_scope(end_point):163 with tf.variable_scope('Branch_0'):164 branch_0 = slim.conv2d(net, 112, [1, 1], scope='Conv2d_0a_1x1')165 with tf.variable_scope('Branch_1'):166 branch_1 = slim.conv2d(net, 144, [1, 1], scope='Conv2d_0a_1x1')167 branch_1 = slim.conv2d(branch_1, 288, [3, 3], scope='Conv2d_0b_3x3')168 with tf.variable_scope('Branch_2'):169 branch_2 = slim.conv2d(net, 32, [1, 1], scope='Conv2d_0a_1x1')170 branch_2 = slim.conv2d(branch_2, 64, [3, 3], scope='Conv2d_0b_3x3')171 with tf.variable_scope('Branch_3'):172 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')173 branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')174 net = tf.concat(175 axis=3, values=[branch_0, branch_1, branch_2, branch_3])176 end_points[end_point] = net177 if final_endpoint == end_point: return net, end_points178 end_point = 'Mixed_4f'179 with tf.variable_scope(end_point):180 with tf.variable_scope('Branch_0'):181 branch_0 = slim.conv2d(net, 256, [1, 1], scope='Conv2d_0a_1x1')182 with tf.variable_scope('Branch_1'):183 branch_1 = slim.conv2d(net, 160, [1, 1], scope='Conv2d_0a_1x1')184 branch_1 = slim.conv2d(branch_1, 320, [3, 3], scope='Conv2d_0b_3x3')185 with tf.variable_scope('Branch_2'):186 branch_2 = slim.conv2d(net, 32, [1, 1], scope='Conv2d_0a_1x1')187 branch_2 = slim.conv2d(branch_2, 128, [3, 3], scope='Conv2d_0b_3x3')188 with tf.variable_scope('Branch_3'):189 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')190 branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')191 net = tf.concat(192 axis=3, values=[branch_0, branch_1, branch_2, branch_3])193 end_points[end_point] = net194 if final_endpoint == end_point: return net, end_points195 end_point = 'MaxPool_5a_2x2'196 net = slim.max_pool2d(net, [2, 2], stride=2, scope=end_point)197 end_points[end_point] = net198 if final_endpoint == end_point: return net, end_points199 end_point = 'Mixed_5b'200 with tf.variable_scope(end_point):201 with tf.variable_scope('Branch_0'):202 branch_0 = slim.conv2d(net, 256, [1, 1], scope='Conv2d_0a_1x1')203 with tf.variable_scope('Branch_1'):204 branch_1 = slim.conv2d(net, 160, [1, 1], scope='Conv2d_0a_1x1')205 branch_1 = slim.conv2d(branch_1, 320, [3, 3], scope='Conv2d_0b_3x3')206 with tf.variable_scope('Branch_2'):207 branch_2 = slim.conv2d(net, 32, [1, 1], scope='Conv2d_0a_1x1')208 branch_2 = slim.conv2d(branch_2, 128, [3, 3], scope='Conv2d_0a_3x3')209 with tf.variable_scope('Branch_3'):210 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')211 branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')212 net = tf.concat(213 axis=3, values=[branch_0, branch_1, branch_2, branch_3])214 end_points[end_point] = net215 if final_endpoint == end_point: return net, end_points216 end_point = 'Mixed_5c'217 with tf.variable_scope(end_point):218 with tf.variable_scope('Branch_0'):219 branch_0 = slim.conv2d(net, 384, [1, 1], scope='Conv2d_0a_1x1')220 with tf.variable_scope('Branch_1'):221 branch_1 = slim.conv2d(net, 192, [1, 1], scope='Conv2d_0a_1x1')222 branch_1 = slim.conv2d(branch_1, 384, [3, 3], scope='Conv2d_0b_3x3')223 with tf.variable_scope('Branch_2'):224 branch_2 = slim.conv2d(net, 48, [1, 1], scope='Conv2d_0a_1x1')225 branch_2 = slim.conv2d(branch_2, 128, [3, 3], scope='Conv2d_0b_3x3')226 with tf.variable_scope('Branch_3'):227 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')228 branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')229 net = tf.concat(230 axis=3, values=[branch_0, branch_1, branch_2, branch_3])231 end_points[end_point] = net232 if final_endpoint == end_point: return net, end_points233 raise ValueError('Unknown final endpoint %s' % final_endpoint)234def inception_v1(inputs,235 num_classes=1000,236 is_training=True,237 dropout_keep_prob=0.8,238 prediction_fn=slim.softmax,239 spatial_squeeze=True,240 reuse=None,241 scope='InceptionV1'):242 """Defines the Inception V1 architecture.243 This architecture is defined in:244 Going deeper with convolutions245 Christian Szegedy, Wei Liu, Yangqing Jia, Pierre Sermanet, Scott Reed,246 Dragomir Anguelov, Dumitru Erhan, Vincent Vanhoucke, Andrew Rabinovich.247 http://arxiv.org/pdf/1409.4842v1.pdf.248 The default image size used to train this network is 224x224.249 Args:250 inputs: a tensor of size [batch_size, height, width, channels].251 num_classes: number of predicted classes.252 is_training: whether is training or not.253 dropout_keep_prob: the percentage of activation values that are retained.254 prediction_fn: a function to get predictions out of logits.255 spatial_squeeze: if True, logits is of shape [B, C], if false logits is of256 shape [B, 1, 1, C], where B is batch_size and C is number of classes.257 reuse: whether or not the network and its variables should be reused. To be258 able to reuse 'scope' must be given.259 scope: Optional variable_scope.260 Returns:261 logits: the pre-softmax activations, a tensor of size262 [batch_size, num_classes]263 end_points: a dictionary from components of the network to the corresponding264 activation.265 """266 # Final pooling and prediction267 with tf.variable_scope(scope, 'InceptionV1', [inputs, num_classes],268 reuse=reuse) as scope:269 with slim.arg_scope([slim.batch_norm, slim.dropout],270 is_training=is_training):271 net, end_points = inception_v1_base(inputs, scope=scope)272 with tf.variable_scope('Logits'):273 net = slim.avg_pool2d(net, [7, 7], stride=1, scope='AvgPool_0a_7x7')274 net = slim.dropout(net,275 dropout_keep_prob, scope='Dropout_0b')276 logits = slim.conv2d(net, num_classes, [1, 1], activation_fn=None,277 normalizer_fn=None, scope='Conv2d_0c_1x1')278 if spatial_squeeze:279 logits = tf.squeeze(logits, [1, 2], name='SpatialSqueeze')280 end_points['Logits'] = logits281 end_points['Predictions'] = prediction_fn(logits, scope='Predictions')282 return logits, end_points283inception_v1.default_image_size = 224...
view-branch.component.ts
Source:view-branch.component.ts
1import { BranchUpdate } from './../../../../interfaces/branch';2import { BranchCombined } from 'src/app/interfaces/branch-combined';3import { HttpErrorResponse } from '@angular/common/http';4import { BranchService } from './../../../../services/branch.service';5import { Component, OnInit } from '@angular/core';6import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';7import { ActivatedRoute, Router } from '@angular/router';8import { BranchForm } from 'src/app/interfaces/branch';9import { Options } from 'ngx-google-places-autocomplete/objects/options/options';10import { last, switchMap } from 'rxjs/operators';11import { AngularFireStorage } from '@angular/fire/storage';12import { MatDialog } from '@angular/material/dialog';13import { ConfirmModalComponent } from 'src/app/components/modals/confirm-modal/confirm-modal.component';14import { MatSnackBar } from '@angular/material/snack-bar';15@Component({16 selector: 'app-view-branch',17 templateUrl: './view-branch.component.html',18 styleUrls: ['./view-branch.component.scss']19})20export class ViewBranchComponent implements OnInit {21 // View / Update Form of Branch Viewed / Updated22 viewBranchForm1: FormGroup;23 // Initialization of view branch container variable24 branchInfo: BranchForm[];25 updatedBranch: any = [];26 branchImage: any;27 selectedImage: any;28 status: any;29 name: any;30 loadingMode: any;31 // Data Members and Methods for Google Maps Places API32 address: any; placeId: any; latitude: any; longitude: any; // Not Displayed33 streetName: any; streetAddress: any; suburb: any; city: any; province: any; country: any; zip: any; // Displayed34 addressOptions = {35 componentRestrictions: { country: "za" },36 types: ["address"]37 } as Options;38 storage: any;39 public handleAddressChange(address: any) {40 // Place id (Not Displayed)41 this.placeId = address.place_id;42 console.log(this.placeId);43 // Latitude coordinate (Not Displayed)44 this.latitude = address.geometry.location.lat();45 console.log(this.latitude);46 // Longitude coordinate (Not Displayed)47 this.longitude = address.geometry.location.lng();48 console.log(this.longitude);49 // Reset street address on method refresh50 this.streetAddress = "";51 // Street Address (full unformatted) (Displayed)52 this.viewBranchForm1.get('branchAddressFull')?.setValue(address.formatted_address);53 // Street number (Displayed i.t.o)54 for (var i = 0; i < address.address_components.length; i++) {55 for (var x = 0; x < address.address_components[i].types.length; x++) {56 if (address.address_components[i].types[x] === "street_number") {57 this.streetAddress = JSON.parse(JSON.stringify(address.address_components[i].long_name)) + " ";58 }59 }60 }61 // Street name (Displayed i.t.o)62 for (var i = 0; i < address.address_components.length; i++) {63 for (var x = 0; x < address.address_components[i].types.length; x++) {64 if (address.address_components[i].types[x] === "route") {65 this.streetAddress += JSON.parse(JSON.stringify(address.address_components[i].long_name));66 }67 }68 }69 // Set Street Name field to combined street name variable (this.streetAddress)70 this.viewBranchForm1.get('branchStreetName')?.setValue(this.streetAddress);71 // Reset suburb on method refresh72 this.suburb = "";73 // Suburb (Displayed)74 for (var i = 0; i < address.address_components.length; i++) {75 for (var x = 0; x < address.address_components[i].types.length; x++) {76 if (address.address_components[i].types[x] === "sublocality") {77 this.viewBranchForm1.get('branchSuburb')?.setValue(address.address_components[i].long_name);78 }79 }80 }81 // Reset city on method refresh82 this.city = "";83 // City (Displayed)84 for (var i = 0; i < address.address_components.length; i++) {85 for (var x = 0; x < address.address_components[i].types.length; x++) {86 if (address.address_components[i].types[x] === "locality") {87 this.viewBranchForm1.get('branchCity')?.setValue(address.address_components[i].long_name);88 }89 }90 }91 // Reset province on method refresh92 this.province = "";93 // Province (Displayed)94 for (var i = 0; i < address.address_components.length; i++) {95 for (var x = 0; x < address.address_components[i].types.length; x++) {96 if (address.address_components[i].types[x] == "administrative_area_level_1") {97 this.viewBranchForm1.get('branchProvince')?.setValue(address.address_components[i].long_name);98 }99 }100 }101 // Reset country on method refresh102 this.country = "";103 // Country (Displayed)104 for (var i = 0; i < address.address_components.length; i++) {105 for (var x = 0; x < address.address_components[i].types.length; x++) {106 if (address.address_components[i].types[x] == "country") {107 this.viewBranchForm1.get('branchCountry')?.setValue(address.address_components[i].long_name);108 }109 }110 }111 // Reset zip on method refresh112 this.zip = "";113 // ZIP (Displayed)114 for (var i = 0; i < address.address_components.length; i++) {115 for (var x = 0; x < address.address_components[i].types.length; x++) {116 if (address.address_components[i].types[x] == "postal_code") {117 this.viewBranchForm1.get('branchZip')?.setValue(address.address_components[i].long_name);118 }119 }120 }121 // Latitude Control (Not displayed)122 this.viewBranchForm1.get('branchLate')?.setValue(this.latitude);123 // Longitude Control (Not displayed)124 this.viewBranchForm1.get('branchLng')?.setValue(this.longitude);125 }126 constructor(127 private fb: FormBuilder,128 private _Activatedroute: ActivatedRoute,129 private branchService: BranchService,130 private storageFb: AngularFireStorage,131 public dialog: MatDialog,132 private route: Router,133 private _snackBar: MatSnackBar,134 ) {}135 // Fetch ID number from URL (Branch ID Number of branch selected)136 passedId = this._Activatedroute.snapshot.paramMap.get("id");137 ngOnInit(): void {138 this.loadingMode = 'query';139 this.branchService.getAllBranchData(this.passedId).subscribe(140 (data: any) => {141 this.loadingMode = 'determinate';142 this.branchInfo = data;143 this.branchImage = this.branchInfo[0].BranchImage;144 this.status = this.branchInfo[0].BranchStatus;145 this.name = this.branchInfo[0].BranchName;146 console.log(data);147 // Populate View Branch Form Group148 this.viewBranchForm1 = this.fb.group({149 branchStatus: [this.branchInfo[0].BranchStatus],150 // Branch Name Control151 branchName: [this.branchInfo[0].BranchName,152 Validators.compose([Validators.required])153 ],154 // Branch Contact Number Control155 branchContactNumber: [this.branchInfo[0].BranchContactNumber,156 Validators.compose([Validators.required])157 ],158 // Branch Email Address Control159 branchEmailAddress: [this.branchInfo[0].BranchEmailAddress,160 Validators.compose([Validators.required, Validators.pattern("^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$")])161 ],162 // Branch Image Control163 branchImage: [this.branchInfo[0].BranchImage,164 Validators.compose([Validators.required])165 ],166 // Branch Main Address Control (Autocomplete)167 branchAddressFull: [this.branchInfo[0].BranchAddressFull,168 Validators.compose([Validators.required])169 ],170 // Branch Street Name Control171 branchStreetName: [{value: this.branchInfo[0].BranchStreetAddress, disabled: true},172 Validators.compose([Validators.required])173 ],174 // Branch Suburb Control175 branchSuburb: [{value: this.branchInfo[0].BranchSuburb, disabled: true},176 Validators.compose([Validators.required])177 ],178 // Branch City Control179 branchCity: [{value: this.branchInfo[0].BranchCity, disabled: true},180 Validators.compose([Validators.required])181 ],182 // Branch Province Control183 branchProvince: [{value: this.branchInfo[0].BranchProvince, disabled: true},184 Validators.compose([Validators.required])185 ],186 // Branch Country Control187 branchCountry: [{value: this.branchInfo[0].BranchCountry, disabled: true},188 Validators.compose([Validators.required])189 ],190 // Branch ZIP Control191 branchZip: [{value: this.branchInfo[0].BranchZip, disabled: true},192 Validators.compose([Validators.required])193 ],194 // Branch Latitude Control (Hidden)195 branchLate: [{value: this.branchInfo[0].BranchLate, disabled: true}],196 // Branch Longitude Control (Hidden)197 branchLng: [{value: this.branchInfo[0].BranchLng, disabled: true}],198 });199 (error: HttpErrorResponse) => {200 console.log(error);201 }}202 )203 }204 async onSubmit() {205 if (this.selectedImage != null) {206 const filePath = `POSImages/${this.selectedImage.name.split('.').slice(0,-1).join('.')}_${new Date().getTime()}`;207 const fileRef = this.storageFb.ref(filePath);208 const task = this.storageFb.upload(filePath, this.selectedImage);209 task.snapshotChanges().pipe(210 last(),211 switchMap(() => fileRef.getDownloadURL())212 ).subscribe((url: any) => {213 this.viewBranchForm1.get('branchImage')?.patchValue(url);214 if (this.viewBranchForm1.invalid) {215 return;216 }217 else {218 this.updateBranch();219 }220 })221 } else {222 this.updateBranch();223 }224 }225 updateBranch() {226 // Confirm New Branch Creation and Add New Branch227 const confirm = this.dialog.open(ConfirmModalComponent, {228 disableClose: true,229 data: {230 heading: 'Confirm Branch Updates',231 message: 'Are you sure you would like to update this branch?'232 }233 });234 confirm.afterClosed().subscribe(resp => {235 this.loadingMode = 'query';236 if (resp) {237 const newBranch: BranchUpdate = this.viewBranchForm1.getRawValue();238 this.branchService.updateBranch(newBranch, this.passedId).subscribe(239 (resp: any) => {240 console.log("Branch Updated Successfully")241 this.route.navigateByUrl('/admin-home/maintain-branch');242 this.displaySuccessMessage("Branch Successfully Updated!")243 this.loadingMode = 'determinate';244 },245 (error: HttpErrorResponse) => {246 if (error.status === 404) {247 this.displayErrorMessage("Unable to Update Branch!")248 }249 else if (error.status === 500 || error.status === 400) {250 this.displayErrorMessage("A branch with that name already exists!")251 } else {252 this.displayErrorMessage("An error occured on the server side!")253 }254 this.loadingMode = 'determinate';255 });256 }257 })258 }259 // Method to reset form to initial values (Discard Changes On Click)260 resetDefault() {261 this.viewBranchForm1.patchValue({262 // Branch Details Section263 branchStatus: this.branchInfo[0].BranchStatus,264 branchName: this.branchInfo[0].BranchName,265 branchContactNumber: this.branchInfo[0].BranchContactNumber,266 branchEmailAddress: this.branchInfo[0].BranchEmailAddress,267 branchImage: this.branchInfo[0].BranchImage,268 // Branch Address Section269 branchAddressFull: this.branchInfo[0].BranchAddressFull,270 branchStreetName: this.branchInfo[0].BranchStreetAddress,271 branchSuburb: this.branchInfo[0].BranchSuburb,272 branchCity: this.branchInfo[0].BranchCity,273 branchProvince: this.branchInfo[0].BranchProvince,274 branchCountry: this.branchInfo[0].BranchCountry,275 branchZip: this.branchInfo[0].BranchZip,276 branchLate: this.branchInfo[0].BranchLate,277 branchLng: this.branchInfo[0].BranchLng278 })279 this.viewBranchForm1.markAsPristine();280 }281 imagePath: any;282 url: any;283 getImageFile(event: any) {284 this.selectedImage = event.target.files[0];285 let fileName = this.selectedImage.name;286 const element: HTMLElement = document.getElementById('file') as HTMLElement;287 element.innerHTML = fileName;288 const files = event.target.files;289 if (files.length === 0)290 return;291 const reader = new FileReader();292 this.imagePath = files;293 reader.readAsDataURL(files[0]);294 reader.onload = (_event) => {295 this.branchImage = reader.result;296 }297 }298 displayErrorMessage(message: string) {299 this._snackBar.open(message, '', {300 duration: 6000,301 panelClass: ['error-snackbar']302 });303 }304 displaySuccessMessage(message: string) {305 this._snackBar.open(message, '', {306 duration: 6000,307 panelClass: ['success-snackbar']308 });309 }...
BranchSolution.js
Source:BranchSolution.js
1var gbSelectedBranchList = [];2var branchSolutionManager = {3 4 GenerateBranchSolutionGrid: function() {5 6 var url = "../Branch/GetActiveBranchSummaryForSbuConfigaration/";7 var column = branchSolutionHelper.GenerateBranchColumns();8 empressCommonManager.GenerateCommonGridWithPaging("divgridBranchSolution", url, column, 50);9 }10};11var branchSolutionHelper = {12 13 initiateBranchSolution: function() {14 15 branchSolutionManager.GenerateBranchSolutionGrid();16 $("#btnAddBranchSol").click(function () {17 branchSolutionHelper.AddBranchSolutionpopInfo();18 19 });20 branchSolutionHelper.createBranchList();21 branchSummaryManager.GenerateBranchGrid();22 branchSummaryHelper.clickEventForEditBranch();23 $("#txtBranchCode").focus();24 branchDetailsHelper.DivisionNameCombo();25 empressCommonHelper.PopulateRegionComboByZoneId(0, "cmbRegion");26 empressCommonHelper.PopulateAreaComboByRegionId(0, "cmbArea");27 $("#cmbDivision").change(function () {28 $("#cmbRegion").data("kendoComboBox").value("");29 $("#cmbArea").data("kendoComboBox").value("");30 var zoneId = $("#cmbDivision").data("kendoComboBox").value();31 if (zoneId == "") {32 zoneId = 0;33 }34 empressCommonHelper.PopulateRegionComboByZoneId(zoneId, "cmbRegion");35 });36 $("#cmbRegion").change(function () {37 $("#cmbArea").data("kendoComboBox").value("");38 var regionId = $("#cmbRegion").data("kendoComboBox").value();39 if (regionId == "") {40 regionId = 0;41 }42 empressCommonHelper.PopulateAreaComboByRegionId(regionId, "cmbArea");43 });44 $("#chkContraEntryApplicable").click(function () { branchSolutionHelper.IsContractEntryApplicable(); });45 },46 47 AddBranchSolutionpopInfo: function () {48 var initPopup = $("#branchDiv").kendoWindow({49 title: 'Add New Branch',50 resizeable: false,51 width: "90%",52 actions: ["Pin", "Refresh", "Maximize", "Close"],53 modal: true,54 visible: false,55 });56 initPopup.data("kendoWindow").open().center();57 },58 59 GenerateBranchColumns: function() {60 return columns = [61 { field: "check_rowForBranch", title: "Select", width: 35, editable: false, filterable: false, sortable: false, template: '#= branchSolutionHelper.checkedDataForBranch(data) #', headerTemplate: '<input type="checkbox" id="checkAllForBranch" />' },62 { filed: "BranchId", title: "BranchId", width: 50, hidden: true },63 { field: "BranchCode", title: "Branch Code", width: 100, sortable: true },64 { field: "BranchName", title: "Branch Name", width: 200, sortable: true },65 { field: "BranchAddress", title: "Address", width: 200, sortable: true }66 ];67 },68 69 createBranchList: function () {70 71 $('#checkAllForBranch').click('click', function (e) {72 gbSelectedBranchList = [];73 var gridSummary = $("#divgridBranchSolution").data("kendoGrid");74 var selectAll = document.getElementById("checkAllForBranch");75 if (selectAll.checked == true) {76 $("#divgridBranchSolution tbody input:checkbox").attr("checked", this.checked);77 $("#divgridBranchSolution table tr").addClass('k-state-selected');78 var gridData = gridSummary.dataSource.data();79 for (var i = 0; i < gridData.length; i++) {80 var obj = gridData[i];81 gbSelectedBranchList.push(obj);82 }83 }84 else {85 $("#divgridBranchSolution tbody input:checkbox").removeAttr("checked", this.checked);86 $("#divgridBranchSolution table tr").removeClass('k-state-selected');87 gbSelectedBranchList = [];88 }89 });// All Row Selection 90 $('#divgridBranchSolution').on('change', '.check_rowForBranch', function (e) {91 var $target = $(e.currentTarget);92 var grid = $("#divgridBranchSolution").data("kendoGrid");93 var dataItem = grid.dataItem($(this).closest('tr'));94 if ($target.prop("checked")) {95 gbSelectedBranchList.push(dataItem);96 } else {97 for (var i = 0; i < gbSelectedBranchList.length; i++) {98 if (gbSelectedBranchList[i].BranchId == dataItem.BranchId) {99 gbSelectedBranchList.splice(i, 1);100 break;101 }102 }103 }104 });105 },106 107 checkedDataForBranch: function (data) {108 if (gbSelectedBranchList.length > 0) {109 var result = gbSelectedBranchList.filter(function (obj) {110 return obj.BranchId == data.BranchId;111 });112 if (result.length > 0) {113 return '<input id="check_rowForBranch" class="check_rowForBranch" type="checkbox" checked="checked"/>';114 }115 else {116 return '<input id="check_rowForBranch" class="check_rowForBranch" type="checkbox"/>';117 //if (data.CompanyId > 0) {118 // gbSelectedBranchList.push(data);119 // return '<input id="check_row" class="check_row" type="checkbox" checked="checked"/>';120 //} else {121 // return '<input id="check_row" class="check_row" type="checkbox"/>';122 //}123 }124 }125 else {126 //if (data.CompanyId > 0) {127 // gbSelectedBranchList.push(data);128 // return '<input id="check_row" class="check_row" type="checkbox" checked="checked"/>';129 //} else {130 // return '<input id="check_row" class="check_row" type="checkbox"/>';131 //}132 return '<input id="check_rowForBranch" class="check_rowForBranch" type="checkbox"/>';133 }134 },135 136 PopulateBranchArray: function(objBranchList) {137 gbSelectedBranchList = [];138 for (var i = 0; i < objBranchList.length; i++) {139 gbSelectedBranchList.push(objBranchList[i]);140 }141 if (objBranchList.length > 0) {142 $("#divgridBranchSolution").data("kendoGrid").dataSource.read();143 }144 },145 IsContractEntryApplicable: function () {146 if ($("#chkContraEntryApplicable").is(':checked') == true) {147 $("#liDebitAccHead").show();148 $("#liCreditAccHead").show();149 }150 else {151 $("#liDebitAccHead").hide();152 $("#liCreditAccHead").hide();153 }154 }...
_BranchTypeWithBranchMappingSummary.js
Source:_BranchTypeWithBranchMappingSummary.js
12var BranchTypeWithBranchMappingSummaryManager = {3 BranchTypeWithBranchMappingDataSource: function () {4 var gridDataSource = new kendo.data.DataSource({5 type: "json",6 serverPaging: true,7 serverSorting: true,8 serverFiltering: true,9 allowUnsort: true,10 //pageSize: 10,11 batch: true,12 //autoSync: true,13 transport: {14 read: {15 url: '../BranchTypeWithBranchMapping/GetBranchTypeWithBranchMappingSummary',16 type: "POST",17 dataType: "json",18 cache: false,19 async: false,20 contentType: "application/json; charset=utf-8"21 },22 parameterMap: function (options, operation) {23 if (operation !== "read" && options.models) {24 return { models: kendo.stringify(options.models) };25 }26 return JSON.stringify(options);27 }28 },29 schema: {30 model: {31 id: "BranchTypeMappingId",32 fields: {33 BranchTypeMappingId: { type: 'number' },34 BranchName: { type: 'text', editable: true },35 BranchType: { type: 'text', editable: true }36 37 },38 },39 data: "Items", total: "TotalCount"40 }41 });42 return gridDataSource;43 }44};45var BranchTypeWithBranchMappingSummaryHelper = {46 GenerateBranchTypeWithBranchMappingGrid: function () {47 48 //$("#divBranchTypeWithBranchMappingSummary").kendoGrid({49 // dataSource: BranchTypeWithBranchMappingSummaryManager.BranchTypeWithBranchMappingDataSource(),50 // pageable: {51 // refresh: true, serverPaging: true, serverFiltering: true, serverSorting: true52 // },53 // filterable: true, sortable: true,54 // columns: BranchTypeWithBranchMappingSummaryHelper.GenerateBranchTypeWithBranchMappingGridColumns(),55 // editable: false,56 // //toolbar: ["create"], selectable: "row,multiple",57 // dataBound: function (e) {58 // }59 //});60 $("#divBranchTypeWithBranchMappingSummary").kendoGrid({61 dataSource: BranchTypeWithBranchMappingSummaryManager.BranchTypeWithBranchMappingDataSource(),62 pageable: {63 refresh: true,64 serverPaging: true,65 serverFiltering: true,66 serverSorting: true67 },68 filterable: true,69 sortable: true,70 columns: BranchTypeWithBranchMappingSummaryHelper.GenerateBranchTypeWithBranchMappingGridColumns(),71 editable: false,72 navigatable: true,73 selectable: "row"74 });75 },76 GenerateBranchTypeWithBranchMappingGridColumns: function () {77 return columns = [78 { field: "BranchName", title: "Branch Name", width: 100 },79 { field: "BranchType", title: "Branch Type", width: 100 },80 {81 field: "Edit", title: "Edit", filterable: false, width: 30, template:82 '<button type="button" value="Edit" id="btnEdit" class="k-button" onClick="BranchTypeWithBranchMappingSummaryHelper.clickEventForEditFunction()"><span class="k-icon k-i-pencil"></span></button>', sortable: false83 },84 85 ];86 },87 populateBranchTypeWithBranchMappingInformation: function (objMapping) {88 $("#hdnBranchMappingId").val(objMapping.BranchTypeMappingId);89 $("#txtBranchType").data("kendoComboBox").value(objMapping.BranchType);90 $("#txtBranchName").data("kendoComboBox").value(objMapping.BranchId);91 },92 clickEventForEditFunction: function () {93 94 var gridData = $("#divBranchTypeWithBranchMappingSummary").data("kendoGrid");95 var selectedItem = gridData.dataItem(gridData.select());96 97 if (selectedItem != null) {98 BranchTypeWithBranchMappingSummaryHelper.populateBranchTypeWithBranchMappingInformation(selectedItem);99 }100}101 102 ...
branch.py
Source:branch.py
1#! /usr/bin/env python2# -*- coding: utf-8 -*-3from django.shortcuts import render, HttpResponseRedirect, HttpResponse4from django.core.urlresolvers import reverse5from django.contrib.auth.decorators import login_required6from branches.models import Branch7from branches.forms import BranchForm8from accounts.permission import permission_verify9import csv10import datetime11from cmdb.api import str2gb12@login_required()13@permission_verify()14def branch_list(request):15 all_branch = Branch.objects.all()16 results = {17 'all_branch': all_branch,18 }19 return render(request, 'branches/branch_list.html', results)20@login_required21@permission_verify()22def branch_del(request):23 branch_id = request.GET.get('id', '')24 if branch_id:25 Branch.objects.filter(id=branch_id).delete()26 branch_id_all = str(request.POST.get('branch_id_all', ''))27 if branch_id_all:28 for branch_id in branch_id_all.split(','):29 Branch.objects.filter(id=branch_id).delete()30 return HttpResponseRedirect(reverse('branch_list'))31@login_required32@permission_verify()33def branch_add(request):34 if request.method == 'POST':35 form = BranchForm(request.POST)36 if form.is_valid():37 form.save()38 return HttpResponseRedirect(reverse('branch_list'))39 else:40 form = BranchForm()41 results = {42 'form': form,43 'request': request,44 }45 return render(request, 'branches/branch_base.html', results)46@login_required47@permission_verify()48def branch_edit(request, branch_id):49 branch_obj = Branch.objects.get(id=branch_id)50 if request.method == 'POST':51 form = BranchForm(request.POST, instance=branch_obj)52 if form.is_valid():53 form.save()54 return HttpResponseRedirect(reverse('branch_list'))55 else:56 form = BranchForm(instance=branch_obj)57 results = {58 'form': form,59 'branch_id': branch_id,60 'request': request,61 }62 return render(request, 'branches/branch_base.html', results)63@login_required64@permission_verify()65def branch_export(request):66 export = request.GET.get("export", '')67 branch_id_list = request.GET.getlist("id", '')68 if export == "part":69 if branch_id_list:70 branch_find = []71 for branch_id in branch_id_list:72 branch_item = Branch.objects.get(id=branch_id)73 if branch_item:74 branch_find.append(branch_item)75 if export == "all":76 branch_find = Branch.objects.all()77 response = HttpResponse(content_type='text/csv')78 now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')79 file_name = 'adminset_branch_' + now + '.csv'80 response['Content-Disposition'] = "attachment; filename="+file_name81 writer = csv.writer(response)82 writer.writerow([str2gb(u'æºæå称'), str2gb(u'æºæå°å'), str2gb(u'è´è´£äºº'), str2gb(u'çµè¯'),83 str2gb(u'说æ'),])84 for p in branch_find:85 writer.writerow([str2gb(p.name), str2gb(p.address), p.owner, p.telphone,86 str2gb(p.owner)])87 return response88@login_required89@permission_verify()90def resource_detail(request, branch_id):91 branch = Branch.objects.get(id=branch_id)92 resources = branch.resource_set.all()93 results = {94 'resources': resources,95 }...
Using AI Code Generation
1var BestFirstSearch = require('./BestFirstSearch');2var graph = new BestFirstSearch.Graph();3var start = graph.setStartNode('start');4var A = graph.addNode('A');5var B = graph.addNode('B');6var C = graph.addNode('C');7var D = graph.addNode('D');8var E = graph.addNode('E');9var F = graph.addNode('F');10var G = graph.addNode('G');11var H = graph.addNode('H');12var goal = graph.setGoalNode('goal');13graph.addUndirectedEdge(start, A, 10);14graph.addUndirectedEdge(start, B, 15);15graph.addUndirectedEdge(A, C, 20);16graph.addUndirectedEdge(A, D, 30);17graph.addUndirectedEdge(B, D, 35);18graph.addUndirectedEdge(B, E, 45);19graph.addUndirectedEdge(C, F, 50);20graph.addUndirectedEdge(D, F, 55);21graph.addUndirectedEdge(D, G, 60);22graph.addUndirectedEdge(E, G, 65);23graph.addUndirectedEdge(E, H, 70);24graph.addUndirectedEdge(F, goal, 100);25graph.addUndirectedEdge(G, goal, 110);26graph.addUndirectedEdge(H, goal, 120);27var result = BestFirstSearch.search(graph, start, goal);28console.log(result.toString());
Using AI Code Generation
1var BestFirstSearch = require('BestFirstSearch');2var path = require('path');3var problem = new BestFirstSearch.Problem({4 isEnd: function (node) {5 return node[0] === 4 && node[1] === 4;6 },7 heuristic: function (node) {8 return Math.abs(node[0] - 4) + Math.abs(node[1] - 4);9 },10 branch: function (node) {11 var x = node[0];12 var y = node[1];13 var children = [];14 if (x > 1) {15 children.push([x - 1, y]);16 }17 if (x < 4) {18 children.push([x + 1, y]);19 }20 if (y > 1) {21 children.push([x, y - 1]);22 }23 if (y < 4) {24 children.push([x, y + 1]);25 }26 return children;27 }28});29var solution = BestFirstSearch.solve(problem);30console.log(solution);
Using AI Code Generation
1var BestFirstSearch = require('./BestFirstSearch');2var Branch = require('./Branch');3var branch = new Branch(1, 1, 0, 0, 0);4var bfs = new BestFirstSearch(branch);5var array = [];6for (var i = 0; i < 100; i++) {7 var branch = new Branch(1, 1, 0, 0, 0);8 var bfs = new BestFirstSearch(branch);9 array.push(bfs);10}11var array2 = [];12for (var i = 0; i < 100; i++) {13 var branch = new Branch(1, 1, 0, 0, 0);14 var bfs = new BestFirstSearch(branch);15 array2.push(bfs);16}17var array3 = [];18for (var i = 0; i < 100; i++) {19 var branch = new Branch(1, 1, 0, 0, 0);20 var bfs = new BestFirstSearch(branch);21 array3.push(bfs);22}23var array4 = [];24for (var i = 0; i < 100; i++) {25 var branch = new Branch(1, 1, 0, 0, 0);26 var bfs = new BestFirstSearch(branch);27 array4.push(bfs);28}29var array5 = [];30for (var i = 0; i < 100; i++) {31 var branch = new Branch(1, 1, 0, 0, 0);32 var bfs = new BestFirstSearch(branch);33 array5.push(bfs);34}35var array6 = [];36for (var i = 0; i < 100; i++) {37 var branch = new Branch(1, 1, 0, 0, 0);38 var bfs = new BestFirstSearch(branch);39 array6.push(bfs);40}41var array7 = [];42for (var i = 0; i < 100; i++) {43 var branch = new Branch(1, 1, 0, 0, 0);44 var bfs = new BestFirstSearch(branch);45 array7.push(bfs);46}47var array8 = [];48for (var i = 0; i < 100; i++) {49 var branch = new Branch(1,
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!