##################################################
# Create Occupancy Trends for Emergency Shelters #
# Rapid Rehousing, and Permanet Housing programs #
# by ProjectName and OrganizationName.           #
##################################################
trendsOfOccupancyByProjectAndOrganization <- function(allDataPath, 
                                                      outputFolder, 
                                                      interval = "week", 
                                                      startDate = "2014-01-01"){
  
  library(plyr)
  
  client <- loadClient(allDataPath)
  
  primaryPersonalIDs <- getPrimaryPersonalID(client)
  primaryPersonalIDs <- sqldf("
                            SELECT
                              PrimaryPersonalID,
                              PersonalID 
                            FROM
                              primaryPersonalIDs")
  
  client <- sqldf("
                  SELECT
                    a.PrimaryPersonalID,
                    b.* 
                  FROM
                    primaryPersonalIDs a 
                  LEFT JOIN
                    client b 
                      ON a.PersonalID=b.PersonalID")
  
  client <- within(client, rm(PersonalID))
  colnames(client)[1] <- "PersonalID"
  client <- unique(client)
  
  enrollment <- loadEnrollment(allDataPath)
  enrollment <- sqldf("SELECT
                        a.PrimaryPersonalID,
                        b.* 
                      FROM
                        primaryPersonalIDs a 
                      LEFT JOIN
                        enrollment b 
                          ON a.PersonalID=b.PersonalID")
  
  enrollment <- within(enrollment, rm(PersonalID))
  colnames(enrollment)[1] <- "PersonalID"
  enrollment <- unique(enrollment)
  
  exit <- loadExit(allDataPath)
  exit <- sqldf("SELECT 
                  a.PrimaryPersonalID, 
                  b.* 
                FROM 
                  primaryPersonalIDs a 
                LEFT JOIN 
                  exit b 
                    ON a.PersonalID=b.PersonalID")
  
  exit <- within(exit, rm(PersonalID))
  colnames(exit)[1] <- "PersonalID"
  exit <- unique(exit)
  
  project <- loadProject(allDataPath)
  inventory <- loadInventory(allDataPath)

  organization <- loadOrganization(allDataPath)
  
  # Add all bed inventories into one (HH without children, HH with children, and HH of children only)
  inventory <- sqldf("
                      SELECT
                        ProjectID,
                        SUM(BedInventory) As 'BedInventory' 
                      FROM
                        inventory 
                      GROUP BY
                        ProjectID
                     ")
  
  allData <- sqldf("
                    SELECT  
                      DISTINCT a.PersonalID, 
                      a.EnrollmentID, 
                      c.ProjectName, 
                      a.EntryDate, 
                      b.ExitDate, 
                      c.ProjectType, 
                      d.BedInventory, 
                      e.OrganizationName
                    FROM 
                      enrollment a
                    LEFT JOIN 
                        exit b
                          ON a.EnrollmentID=b.EnrollmentID
                    LEFT JOIN 
                        project c
                          ON a.ProjectID=c.ProjectID
                    LEFT JOIN 
                        inventory d
                          ON c.ProjectID=d.ProjectID
                    LEFT JOIN 
                        organization e
                          ON c.OrganizationID=e.OrganizationID
                    WHERE RelationshipToHoH != 'NA'")
  
  remove(client, enrollment, exit, project, primaryPersonalIDs)
  
  # Gets max and min date
  bfr <- sqldf("
                SELECT 
                  MIN(EntryDate) As MinimumDate
                FROM 
                  allData
               ")
  
  min_date <- ""
  if(startDate == ""){
    min_date <- as.character(bfr[1,1])  
  } else {
    min_date <- startDate
  }
  bfr <- sqldf("
                SELECT 
                  MAX(EntryDate) As MaximumDate 
               FROM 
                  allData
               ")

  max_date <- as.character(bfr)
  
  intervalConstant <- switch(interval,
                             week = 7,
                             month = 30,
                             quarter = 120)
  
  numberOfIntervals <- switch(interval,
                              week = as.integer(getWeeksBetween(min_date, max_date)),
                              month = as.integer(getMonthsBetween(min_date, max_date)),
                              quarter = as.integer(getQuartersBetween(min_date, max_date)))
  
  allData$EntryDate <- as.Date(allData$EntryDate)
  allData$ExitDate <- as.Date(allData$ExitDate)

  projectTypeList <- unique(allData$ProjectType[!is.na(allData$ProjectType)])

  # Calculate occupancy by ProjectName
  for(projectType in projectTypeList) {
    
    projectTypeName <- as.character((makeProjectTypeReadableVector(list(projectType))))
    
    thisProjectTypeData <- allData[allData$ProjectType == projectType,]
    
    # Inialize dataframe with all ProjectNames
    projectEnrollmentsTrend <- unique(data.frame(thisProjectTypeData$ProjectName))
    colnames(projectEnrollmentsTrend)[1] <- "ProjectName"
    
    # Attach project bed data 
    thisProjectBedData <- unique(data.frame(allData$ProjectName, allData$BedInventory))
    colnames(thisProjectBedData)[1] <- "ProjectName"
    colnames(thisProjectBedData)[2] <- "BedInventory"
    
    for(i in 0:numberOfIntervals) {
      intervalStartDate <- as.Date(min_date) + i * intervalConstant
      intervalEndDate <- as.Date(min_date) + (i + 1) * intervalConstant
      
      activeEnrollment <- subset(thisProjectTypeData, 
                                 EntryDate <= as.Date(intervalStartDate) &
                                   (ExitDate >= as.Date(intervalEndDate) |
                                      is.na(ExitDate)))
      
      projectCount <- count(activeEnrollment, ProjectName)
      colnames(projectCount)[2] <- as.character(intervalStartDate)
    
      thisCountWithBeds <- merge(x = projectCount, y = thisProjectBedData, by = "ProjectName", all.x = TRUE)
      thisCountWithBeds$OccupancyPercentage <- round(thisCountWithBeds[,2] / thisCountWithBeds[,3], digits = 4)
      projectCount <- data.frame(thisCountWithBeds$ProjectName, thisCountWithBeds$OccupancyPercentage)
      colnames(projectCount)[1] <- "ProjectName"
      colnames(projectCount)[2] <- "Occupancy"
      
      averageDf <- sqldf("
                         SELECT 
                            'Average' As 'ProjectName',
                            AVG(Occupancy) As 'Occupancy'
                         FROM 
                            projectCount
                         ")
      
      projectCount <- rbind(projectCount, averageDf)
      colnames(projectCount)[2] <- as.character(intervalStartDate)

      projectEnrollmentsTrend <- merge(x = projectEnrollmentsTrend, y = projectCount, by = "ProjectName", all.x = TRUE)
    }

    tmpColMeans <- numcolwise(mean, na.rm = TRUE)(projectEnrollmentsTrend)
    tmpColMeans$ProjectName <- "Average"
    projectEnrollmentsTrend <- rbind(projectEnrollmentsTrend, tmpColMeans)

    projectEnrollmentsTrend <- t(projectEnrollmentsTrend)
    colnames(projectEnrollmentsTrend) <- projectEnrollmentsTrend[1,]
    projectEnrollmentsTrend <- projectEnrollmentsTrend[-1,]
    
    write.csv(projectEnrollmentsTrend, 
              paste(outputPublicPath, 
                    "/ProjectsEnrollmentsTrend_ProjectType_", 
                    projectTypeName, 
                    ".csv", 
                    sep=""), 
              na = "", row.names = TRUE) 
  }


  # Bed occupancy by OrganizationName 
  for(projectType in projectTypeList) {
    
    projectTypeName <- as.character((makeProjectTypeReadableVector(list(projectType))))
    
    thisOrganizationData <- allData[allData$ProjectType == projectType,]
    organizationEnrollmentsTrend <- unique(data.frame(thisOrganizationData$OrganizationName))
    colnames(organizationEnrollmentsTrend)[1] <- "OrganizationName"
    
    thisOrganizationBedData <- unique(data.frame(allData$OrganizationName, allData$BedInventory))
    colnames(thisOrganizationBedData)[1] <- "OrganizationName"
    colnames(thisOrganizationBedData)[2] <- "BedInventory"
    
    for(i in 0:numberOfIntervals) {
      intervalStartDate <- as.Date(min_date) + i * intervalConstant
      intervalEndDate <- as.Date(min_date) + (i + 1) * intervalConstant
      
      activeEnrollment <- subset(thisOrganizationData, 
                                 EntryDate <= as.Date(intervalStartDate) &
                                   (ExitDate >= as.Date(intervalEndDate) |
                                      is.na(ExitDate)))
      
      projectCount <- count(activeEnrollment, OrganizationName)
      colnames(projectCount)[2] <- as.character(intervalStartDate)
    
      thisCountWithBeds <- merge(x = projectCount, y = thisOrganizationBedData, by = "OrganizationName", all.x = TRUE)
      thisCountWithBeds$OccupancyPercentage <- round(thisCountWithBeds[,2] / thisCountWithBeds[,3], digits = 4)
      projectCount <- data.frame(thisCountWithBeds$OrganizationName, thisCountWithBeds$OccupancyPercentage)
      colnames(projectCount)[1] <- "OrganizationName"
      colnames(projectCount)[2] <- "Occupancy"

      projectCount <- sqldf("SELECT 
                              OrganizationName, 
                              AVG(Occupancy) As 'Occupancy'
                            FROM 
                              projectCount 
                            GROUP BY 
                              OrganizationName")
      
      colnames(projectCount)[2] <- as.character(intervalStartDate)

      organizationEnrollmentsTrend <- merge(x = organizationEnrollmentsTrend, y = projectCount, by = "OrganizationName", all.x = TRUE)
    }

    tmpColMeans <- numcolwise(mean, na.rm = TRUE)(organizationEnrollmentsTrend)
    tmpColMeans$OrganizationName <- "Average"
    organizationEnrollmentsTrend <- rbind(organizationEnrollmentsTrend, tmpColMeans)

    organizationEnrollmentsTrend <- t(organizationEnrollmentsTrend)
    colnames(organizationEnrollmentsTrend) <- organizationEnrollmentsTrend[1,]
    organizationEnrollmentsTrend <- organizationEnrollmentsTrend[-1,]
    
    write.csv(organizationEnrollmentsTrend, paste(outputPublicPath, "/OrganizationEnrollmentsTrend_ProjectType_", projectTypeName, ".csv", sep=""), na = "", row.names = TRUE) 
  }
}

trendsOfOccupancyByProjectAndOrganization(allDataPath, outputPublicPath)

Test2

God created the world perfect, we fucked it up

Why does bad shit happen in the world?

Take someone makes a choice to heroine. It doesn’t take more than a few times to make a habit. Then it becomes an addiction. Now, a person has less free will. But mroe than that, the world is a worse place because of the choice. There are drug dealers who provide and cops who are disgruntled at dealing with it.

Even if the world was made perfect, we’ve fucked it up–because we have freewill to do so.

The Hidden God

Why does god remain hidden? It is necessary for freewill and reason to coexist. If a reasonable human saw God in fullest, there is no longer freewill. The only choices which make sense are those which align with his omnipotent will.

Doubting Thomas

This letter isn’t for you. If you’re an aethist, it’ll piss you off. If you are a Christian, it’ll piss you off. If you are a spiritualist, it’ll piss you off. If you are agonostic, well, I’m not sure–it depends how open minded you are.

Can you doubt yourself?

Nor must we overlook the probability of the constant inculcation in a belief in God on the minds of children producing so strong and perhaps an inherited effect on their brains not yet fully developed, that it would be as difficult for them to throw off their belief in God, as for a monkey to throw off its instinctive fear and hatred of a snake.

Doubt is a skill

  • Dillusional battles a good source of practice.
  • Schizophrenic man being able to doubt his reality
  1. Vehement reaction to an idea is ofte an in indicator of non-reason
  2. Dissonance bias and consance bias
  3. Understading others Vehemence
    • Believe you will go to hell
    • Believe you will confine the world with abusive morality (aka, witch trials)
  4. Philosophy is a house of cards
  5. Staked facts have little use

C.S. Lewis on Time

http://www2.esm.vt.edu/~sdross/text/beyondtime.html

If you picture Time as a straight line along which we have to travel, then you must picture as the whole page on which the line is drawn. We come to the parts of the line one by one: we have to leave A behind before we get to B, and cannot reach C until we leave B behind. God, from above or outside or all around, contains the whole line, and sees it all.

Sigmound Brower – Evolution

Darwin on God

With respect to the theological view of the question; this is always painful to me.— I am bewildered.– I had no intention to write atheistically. But I own that I cannot see, as plainly as others do, & as I [should] wish to do, evidence of design & beneficence on all sides of us. There seems to me too much misery in the world. I cannot persuade myself that a beneficent & omnipotent God would have designedly created the Ichneumonidæ with the express intention of their feeding within the living bodies of caterpillars, or that a cat should play with mice. Not believing this, I see no necessity in the belief that the eye was expressly designed. On the other hand I cannot anyhow be contented to view this wonderful universe & especially the nature of man, & to conclude that everything is the result of brute force. I am inclined to look at everything as resulting from designed laws, with the details, whether good or bad, left to the working out of what we may call chance. Not that this notion at all satisfies me. I feel most deeply that the whole subject is too profound for the human intellect. A dog might as well speculate on the mind of Newton.— Let each man hope & believe what he can.

Higgs-Boson

  1. Infinite root-cause analysis
  2. Incomplete physics theory without Higgs-Boson
  3. God is non-falsafible
  4. Insert God into a system and test it
Robber Board v3

2017-12-24 – v3

This is an update on the Robber Board I’ve been slowly working on. Its a small little bells-and-whistles board which is meant to be a test platform for my Lumi wireless AVR uploder.

I’ve almost finished testing the Robber board v3. A few changes:

ISP Key

I’ve added a special ISP header to the board. It works with Tiny AVR-ISP pogo-pin programming adapter

It’s a bit of a pain to solder, but it’s pretty darn sweet once it’s in place. Of course, the header is backwards. I’m going to be humble and blame myself for not checking the pinout, but I ended up vertically switching the pins. This caused a few hours of frustration.

Besides that, the rest of the board works.

Footprint

Robber Board v3

  • M502 Resets to factory settings. While using EEPROM this must be done every time the firmware is changed and uploaded.
  • G33 is auto-calibration. It assumes the probe is in the right place and calculates offsets for everything else. It is the opposite from g29, which assumes everything is in the right place and the calculates where the probe is, which is used with an offset to find the nozzel head.
  • It doesn’t look like G33 currently has support for probe offset.

Not sure if this issue, but I had the Allen Key probe setting enabled. However, this is probably better labeled “Allen Key Method”

/**
 * A Fix-Mounted Probe either doesn't deploy or needs manual deployment.
 *   (e.g., an inductive probe or a nozzle-based probe-switch.)
 */
#define FIX_MOUNTED_PROBE

Instead, if you are manually deploying the Allen Key, then use.

/**
 * A Fix-Mounted Probe either doesn't deploy or needs manual deployment.
 *   (e.g., an inductive probe or a nozzle-based probe-switch.)
 */
#define FIX_MOUNTED_PROBE