Wednesday, April 8, 2020

Runge-Kutta, SIR - susceptible (S), infected (I), and resistant (R)


Ref:

  1. https://www.geeksforgeeks.org/runge-kutta-4th-order-method-solve-differential-equation/

The formula basically computes next value yn+1 using current yn plus weighted average of four increments.
  • k1 is the increment based on the slope at the beginning of the interval, using y
  • k2 is the increment based on the slope at the midpoint of the interval, using y + hk1/2.
  • k3 is again the increment based on the slope at the midpoint, using using y + hk2/2.
  • k4 is the increment based on the slope at the end of the interval, using y + hk3.



SIR model 

REF: 

  1. Susceptible (S). The individual hasn't contracted the disease, but she can be infected due to transmisison from infected people
  2. Infected (I). This person has contracted the disease
  3. Recovered/Deceased (R). The disease may lead to one of two destinies: either the person survives, hence developing inmunity to the disease, or the person is deceased.
There are many versions of this model, considering birth and death (SIRD with demography), with intermediate states, etc. However, since we are in the early stages of the COVID-19 expansion and our interest is focused in the short term, we will consider that people develops immunity (in the long term, immunity may be lost and the COVID-19 may come back within a certain seasonality like the common flu) and there is no transition from recovered to the remaining two states. With this, the differential equations that govern the system are:
dSdt=βSIN

dIdt=βSINγI

dRdt=γI

Where β is the contagion rate of the pathogen and γ is the recovery rate.

Thursday, April 2, 2020

ExportAs feature in angular, Angular selector


Ref:

for better uderstanding 

exportAs is used for directives, see: http://plnkr.co/edit/IlLtBY7Ic9yKiRIpjukf?p=preview
@Directive({
  selector: "div",
  exportAs: "myDiv"
})
class MyDiv {

  constructor(private element: ElementRef, private renderer: Renderer) {
  }

  toUpper() {
    return this.renderer.setElementStyle(this.element.nativeElement, "text-transform", "uppercase");
  }

  toLower() {
    return this.renderer.setElementStyle(this.element.nativeElement, "text-transform", "lowercase");
  }

  reset() {
    return this.renderer.setElementStyle(this.element.nativeElement, "text-transform", "");
  }
}

Angular selector

Selector property of @Component decorator support, element selector, attribute selector and class selector:
1. Element selector:
@Component({
 selector: 'app-servers'
})
Usage: <app-servers></app-servers>
2. Attribute selector:
@Component({
 selector: '[app-servers]'
})
Usage: <div app-servers></div>
3. Class selector:
@Component({
 selector: '.app-servers'
})
Usage: <div class="app-servers"></div>
Note: Angular 2 does not support id and pseudo selectors





Monday, March 30, 2020

ng-template, ng-content, ViewContentRef


  1. https://www.concretepage.com/angular-2/angular-4-ng-template-example  (VVI for ng-template)
  2.  https://netbasal.com/angular-2-understanding-viewcontainerref-acc183f3b682 (VVI viewContentRef , https://angular.io/api/core/ViewContainerRef )
  3. https://stackoverflow.com/questions/42420957/angular-setting-context-with-createembeddedview  (how to pass data from createEmbedded view from ts file)
viewContainerRef Represents the ng-container.


So as a rule of thumb you can go for the following:
  • { static: true } needs to be set when you want to access the ViewChild in ngOnInit.
  • { static: false } can only be accessed in ngAfterViewInit. This is also what you want to go for when you have a structural directive (i.e. *ngIf) on your element in your template.

In most cases you will want to use {static: false}. Setting it like this will ensure query matches that are dependent on binding resolution (like structural directives *ngIf, etc...) will be found.
Example of when to use static: false:
@Component({
  template: `
    <div *ngIf="showMe" #viewMe>Am I here?</div>
    <button (click)="showMe = !showMe"></button>
  ` 
})
export class ExampleComponent {
  @ViewChild('viewMe', { static: false })
  viewMe?: ElementRef<HTMLElement>; 

  showMe = false;
}
The static: false is going to be the default fallback behaviour in Angular 9. Read more here and here
The { static: true } option was introduced to support creating embedded views on the fly. When you are creating a view dynamically and want to acces the TemplateRef, you won't be able to do so in ngAfterViewInit as it will cause a ExpressionHasChangedAfterChecked error. Setting the static flag to true will create your view in ngOnInit.

Monday, February 17, 2020

Regular expression



^(?=\d{10})[1]\d{1,9}|^\d{1,9}

^ = startting string
(?=\d{10}) = check the string size is 10 or not


Ref :
  1. https://www.regextester.com/96826
  2. https://www.rexegg.com/regex-quickstart.html

Autoboxing and Unboxing

  Autoboxing  is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper cl...