What I did the last 3 years

I had no time to write something for a while, the goal of this post is to summarize what did and what I am doing!

1. Master’s degree: Data Analytics and Business Intelligence

I decided to come back to the university to study Data Science I completed the following studies:

Master’s degree Business Intelligence 2018 – 2019 (Universitat Oberta de Catalunya – Spain)
– Gather and analyze information relevant to a company’s environment.
– Business oriented data analytics. (Customer and operations analytics)
– Use of procedures, skills, applications, tools and practices to support decision-making.

Post degree Data Analytics and Big Data 2016 – 2018 (Universitat Oberta de Catalunya – Spain)
– Data mining, data analytics and visual analytics.
– Data management, data governance and Big Data.
– Machine learning and artificial intelligence.

During that time I was involved in a couple of personal projects beside my job in OMICRON Electroncis.

2. Data Analyst hobbyist

I supported the eSport club x6tence doing data analysis for Clash Royale. To do this a webpage and a database SQLServer in Azure was used to do the data acquisition and PowerBI to do the Data Analysis.

This project was excelent to apply a lot of things that I was learning during my studies, special mention to PowerBI.

3. Cloud, web and phone apps development: Doctor Decks

Doctor Decks was a software to find good combinations of cards for the game Clash Royale. The product was available in the web and also as a phone app: Windows universal, iOS and Android. This was an excelent project to learn a lot about data analysis and improve my knowledge about Angular and Xamarin.

The web has thousands of visits everyday and the app 1M downloads!

After this long break my goal is to write again in this post with a strong focus on Data Analysis.

Advertisements

Learning Azure DocumentDB – Published!

During the last months I had the pleasure to do the technical review of a book about DocumentDB written by Riccardo Becker.  

It is available at pucktpub now!

https://www.packtpub.com/big-data-and-business-intelligence/learning-azure-documentdb

2467EN_B04638_Microsoft Azure DocumentDB

Swift 2 examples – #11 Loading images from the Photo Library and the Camera

This post is part of my collection: Swift 2 – For Beginners.

In this example we will see how to load photos in our application from the Photo Library and from the camera.

To open the photo library to pickup a photo we need a UIImagePickerController. Our controller can be the delegate. To do that we have to implement the protocols: UINavigationControllerDelegate and UIImagePickerControllerDelegate.

This code creates UIImagePickerController and use the method presentViewController to open the Photo Library:

  func selectImage(){
        let imagePickerController = UIImagePickerController()
        imagePickerController.delegate = self

        imagePickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
        imagePickerController.allowsEditing = true

        self.presentViewController(imagePickerController, animated: true, completion: nil)
    }

Once the user selects a photo our controller will be called back. Let’s implement a function that will load the selected image into a imageView:

   // Pick image finished, show selected image in a imageView
    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
        // Show image
        imageView.image = image
        self.dismissViewControllerAnimated(true, completion: nil)
    }

To take a new photo using the camera we just change the value of imagePickerController.sourceType. Instead of PhotoLibrary we use Camera.

We can add a parameter to the previous function to specify the source of our image:

    func selectImage(from source: UIImagePickerControllerSourceType){
        let imagePickerController = UIImagePickerController()
        imagePickerController.delegate = self

        imagePickerController.sourceType = source
        imagePickerController.allowsEditing = true

        self.presentViewController(imagePickerController, animated: true, completion: nil)
    }

Complete example:

import UIKit

class ViewController: UIViewController,

    // 1 Allows navigation to camera or photo library to pick up a photo
    // used to set this controller as delegate of UIImagePickerController
    UINavigationControllerDelegate, UIImagePickerControllerDelegate
{

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBOutlet weak var imageView: UIImageView!

    @IBAction func addFromCamera(sender: AnyObject) {
        selectImage(from: UIImagePickerControllerSourceType.Camera)
    }

    @IBAction func addFromLibrary(sender: AnyObject) {
        selectImage(from: UIImagePickerControllerSourceType.PhotoLibrary)
    }

    // 2 Show image picker or camera app
    func selectImage(from source: UIImagePickerControllerSourceType){
        let imagePickerController = UIImagePickerController()
        imagePickerController.delegate = self

        imagePickerController.sourceType = source
        imagePickerController.allowsEditing = true

        self.presentViewController(imagePickerController, animated: true, completion: nil)
    }

    // 3 Pick image finished, show selected image
    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
        // Show image
        imageView.image = image
        self.dismissViewControllerAnimated(true, completion: nil)
    }
}

TypeScript – Introduction

It is time to start learning the language of the future: TypeScript

There are a lot of online resources to learn the language, here I just share a small piece of code with the basics of the language:

//---------------
// 1 Basic types
//---------------
var myBooleanVar: boolean = false;
var myNumberVar: number = 29;
var myStringVar: string = "Juan Carlos";

// 1.1 Arrays
var myArrayVar: number[] = [1, 2, 3];
var myArrayVar: Array<number> = [1, 2, 3];

// 1.2 Enumerations
enum Direction { Up, Down, Left, Right };
var myDirectionVar: Direction = Direction.Up;

// 1.3 Any
var myAnyTypeVar: any = "I am a text";
myAnyTypeVar = false; // before it was string, now a boolean

// 1.4 Void
function log(msg: string): void {
	console.log(msg);
	// this functions returns nothing
}

//---------------
// 2 Interfaces
//---------------
interface IPerson {
	name: string;
	age?: number; // optional parameter
}

function sayHello(person: IPerson) {
	console.log(person.name);
	if (person.age) {
		console.log("Your age is " + person.age)
	}
}

// myVar has no type but has all the fields that a 
// Person should have. Therefore is a Person (duck typing)
var myVar = { name: "Juan Carlos" };
sayHello(myVar);

// 2.1 Interfaces extends
interface IStudent extends IPerson {
	studentId: number;
}

// 2.2 Interfaces indexes
interface Friends {
	[index: number]: IPerson;
	length: number;
}

// 2.3 Interfaces with functions/methods
interface PeopleService {
	getPersonId(person: IPerson): number;
	// a function that has a Person has parameter and return a boolean
	(newFriend: IPerson): boolean;
}

//---------------
// 3 Classes
//---------------

// 3.1 Interfaces implementation
interface IVehicle {
	move(direction: Direction);
	registrationNumber: number;
}

class Vehicle implements IVehicle {
	registrationNumber: number;

    constructor(id: number) {
		this.registrationNumber = id;
	}

	move(direction: Direction) {
		console.log("Moving" + direction);
	}
}

// 3.2 Classes Extends
class Car extends Vehicle {
	// by default all public
	private numberOfWheels: number = 4;
	speed: number = 120;
	
	// method override
	move(direction: Direction) {
		console.log("Speed = " + this.speed);
		// call base
		super.move(direction);
	}
}

var myCar: IVehicle = new Car(1234);
myCar.move(Direction.Up);

// 3.3 Classes, define class fields in constructor 
// add public or private to the parameter
class Motorbike implements IVehicle {
	private numberOfWheels: number = 2;
	
	// the constructor defines a public field 'registrationNumber'
    constructor(
		public registrationNumber: number,
		// define a private field with the value passed as parameter
		// if no value specified, the field as the value 90
		private speed: number = 90) {
	}

	move(direction: Direction) {
		console.log("Moving the motorbike" + direction);
	}
}

// 3.4 Accesors and static fields
class Plane implements IVehicle {
	// Static field
	static minSpeed: number = 100;
	static speedCorrectionFactor: number = 0.8;
	
	constructor(
		public registrationNumber: number,
		private _speed: number = 300) {
	}

	// speed getter
	get getSpeed(): number {
		// for some reason the public speed is 80%
		// of the realone
        return this._speed * Plane.speedCorrectionFactor;
    }

	// speed setter
    set setSpeed(newSpeed: number) {
		if (newSpeed > Plane.minSpeed) {
			this._speed = newSpeed;
		}
	}

	move(direction: Direction) {
		console.log("Flying! " + direction);
	}
}

Resources:
http://www.typescriptlang.org/Handbook

What’s new in C# 6.0

I just installed Visual Studio 2015 Preview on a Windows 10 tech. preview, the first thing I wanted to try out was C# 6.0.

Source code

VisualStudio2015 in Windows10

VisualStudio 2015 in Windows10

The are a lot of videos and posts on internet about the new features of C# 6.0. The goal of this post is to test them by myself and share my impressions. I will use this post in the future as a personal reference for C# 6.0 new features.

C# 6.0 new feautures

This is the list of new features I have collected so far:

  • Getter only auto properties
  • Auto-Initialization of properties
  • Calculated properties with body expressions
  • Null conditional operators ?.
  • Operator nameof()
  • Strings projections
  • Exceptions filters
  • Await in catch and finally
  • Index initializers

I wrote a small sample class that I will use as an example to test the new features.

This is the C# 5 sample class:

using System;

namespace ConsoleApplication1
{
    public class Person
    {
        public Person(string name, int age)
        {
            if (name == null)
            {
                throw new NullReferenceException("name");
            }

            Name = name;
            Age = age;
            Id = GetNewId();
        }

        public string Name { get; set; }
        public int Id { get; private set; }
        public int Age { get; set; }

        public event EventHandler Call;

        protected virtual void OnCall()
        {
            EventHandler handler = Call;
            if (handler != null) handler(this, EventArgs.Empty);
        }

        public int GetYearOfBirth()
        {
            return DateTime.Now.Year - Age;
        }

        public JObject ToJSon()
        {
            var personAsJson = new JObject();

            personAsJson["id"] = this.Id;
            personAsJson["name"] = this.Name;
            personAsJson["age"] = this.Age;

            return personAsJson;
        }

        #region Get new person id

        private static int lastId;

        private static int GetNewId()
        {
            lastId++;
            Logger.WriteInfo(string.Format("New Id = {0}", lastId));
            return lastId;
        }

        #endregion
    }
}

Applying C# 6.0 new features to a C# 5.0 class:

Now lets go throw the list of new features and apply them to our sample class:

Getter only auto properties

We can remove “private set” from read-only properties, properties with only a “setter” can be initialized only from the constructor or with auto-initialization.

public int Id { get; }     

Auto-Initialization of properties

Using auto initialization we can auto initialize the Id property calling a method. It is also possible to set a default value to editable properties:

public int Id { get; } = GetNewId();    
public int Age { get; set; } = 18;    

Calculated properties with body expressions

It is common to have a lot of single line calculated properties or methods on our code. In lambda expressions it was already possible to write only the value to return. Now this is also possible in normal methods:

Our “GetYearOfBirth” method can be re-write like this:

     
public int GetYearOfBirth => DateTime.Now.Year - Age;

Note that if the method has not parameters we can also avoid the parentheses.

Null conditional operators ?.

Continue reading