Showing posts with label cs. Show all posts
Showing posts with label cs. Show all posts

Looping Through Data


I don't know about you, but I often organize students with google sheets. I use rows for each student and columns for information related to the student. Sometimes I need to push this informatiuon back to students or parents. Sometimes I have do something else with the information. It’s helpful to know how to get the data and work with it in a loop.

Spreadsheets are a two dimensional arrays. There is information in Rows, dimension 1,  and information in columns, dimension 2. We can target each cell by knowing the proper row and column.

We can also loop through each row and do something with the data. 

Computers start counting from 0. Google Sheets starts counting the informational rows and columns from 1. I will also use my own label in row 1 to identify the column number. This way I can insert columns and move them around and still retrieve the same information. Let’s start with identifying the columns by our own labels and setting the column number to a variable which makes sense to us. 

function loopThroughData(){

  var ss= SpreadsheetApp.getActiveSpreadsheet();
  var sheet= SpreadsheetApp.getActiveSheet();
  var emailcol = getColumnByName(sheet, "Email");
  Logger.log(emailcol);
}

function getColumnByName(sheet, name) {
  var range = sheet.getRange(1, 1, 1, sheet.getMaxColumns());
  var values = range.getValues();
  for (var row in values) {
    for (var col in values[row]) {
      if (values[row][col] == name) {
        return parseInt(col)+1;
      }
    }
  }
}

A function called getColumnByName is used in our loopThroughData function. It’s used with two variables pushed into it. The first is the sheet we are working on and the second is the column name. This function runs and will return the column number if the column name is found. The program returns to the loopThroughData function and completes the script Logging the column number. 
This begins to give us some flexibility with the sheet. We can add and move columns and not work about breaking our program. We can run it and we’ll see the column number returned in the log. The intent here is to be able to loop through and use data in a full sheet. We know how to get the column numbers but what about the rows and the rest of the data. 

Efficiency in code so far doesn’t seem like a big deal. We’ve looked at very little data. But if we were to use an entire sheet composed of the maximum 5,000,000 cells (as of the newest 2018 update) we need to start being aware of how long each step of code takes. Even if we consider using up to 1,000,000 cells it can take longer than we expect to finish our script. Attendance data can exist in large data sets. Consider a school of 400 students * 180 school days * 7 classes each of attendance. 504,000 cells of data. If a step of our program takes .01 seconds it will take 5,040 seconds to complete or 84 minutes or 1 hour and 24 seconds. And that’s just one step. So while we can pull each cell individually with sheet.getRange(row, column).getValue() we need to ask ourselves if it’s the most efficient. 

Our loop will instead pull all the data, once, and reference it in the computer memory. Below I concentrate on our main function our getColumnByName should remain in the script. I usually keep functions I use in larger functions at the bottom on all my scripts. 

function loopThroughData(){
  var ss= SpreadsheetApp.getActiveSpreadsheet();
  var sheet= SpreadsheetApp.getActiveSheet();
  var emailcol = getColumnByName(sheet, "Email");
  var data = sheet.getDataRange().getValues();
  for (var i =1;i<data.length;i++){
    Logger.log(data[i][emailcol-1]);
  }
}

The variable data is the used area of the sheet. It provides data in a matrix format. The first referenced data index is the row. The second is the column. We would use a reference to the index number of the row and column to reference a value. The index starts from 0 so row 0 is our header. In the sheet it’s row 1.Our column   numbers compared to the sheet are all offset by -1. To return the header cell containing “Email” we can use row 0 and column emailcol-1. We’d write it like this in our script.

data[0][emailcol-1]

The square brackets [] are used to indicate an index number. They can be strung together to reference indexes of indexes.

Now that we have a concept of indexes we are going to use a for loop to walk through our rows of data. For loops have three inputs to get them started. First a variable to count with set to the first number; var i = 0. Then the end of the loop as an expression. I usually think “while” in my head as I write it; i<data.length. And finally an increment for our counting variable to increase by with each loop; i++. JavaScript allows the short hand of using ++ to increment by 1 rather than i=i+1.

Here’s our initial for loop. 
for (var i =1;i<data.length;i++)

The loop needs to know what to do each time around. We put an action inside curly brackets { and }. We can also use the i variable in our action. 

data[i][emailcol-1]

With data we are saying return the second row (computers start from 0 and i starts being set as 1 se we are skipping our header row) and the column of the email (we assigned emailcol as the sheet column which is now offset in data by -1 so we offset the email column number by -1).

Putting it all together we can loop through the data and do something with it. Above we are returning whatever is in the email column and putting it in the log. We can instead send emails, create slides, make websites or many other operations which we would do manually but take a lot of time. Here's a sample sheet that sends out emails. 
Sample

Enjoy!

Applying Digital Skills in the everyday classroom

Our students come to us with interests, some with passions. How can we harness that interest/passion and teach them the digital skills they need for success in the workplace? 



Google has begun supporting the digital learner with a framework of video centered activities to teach the digital skills of GSuite while engaging with curriculum content. Applied Digital Skills has been released for the CSFirst team to teach the GSuite along side some virtually authentic tasks. Students have the opportunity to explore data analysis while creating a concept for the next big blockbuster movie, make a map of some favorite places from a sheet, or do some organized college research.

What Google Provides:
  • 20 units of authentic tasks which can be tailored to the student. 
  • Lesson plans for the teacher with actionable tips on teaching each one. 
  • Rubrics: Customizable with created project samples. 
  • Tracking of student activity. 
  • Extension tasks. 
  • Videos with transcripts (transcripts only can be translated) of demonstrated instruction.
  • Steps bulleted as a summery of action. 

What you need to figure out:
  • How work will be turned in. I recommend using Google Classroom and linking the activity as a resource. Materials are some times built on top of so if you are taking a series of assessment snapshots ask students to turn in a copy of their work so you don't have to rely on Version History. 
  • What topic(s) you will center the lesson around. Not all lessons provide the opportunity to frame the work around a content topic. Be sure to review the work first. 
  • A full set of devices for your class to use. While this can be done in small groups it's best geared to a 1-to-1 environment. It's developed to support students working at their own pace which means they need the digital ability to do so. Devices do work for this so if you are a BYOD environment even with cell phones it can function for you. 
  • How to do the work students are doing. Don't be fooled into thinking this is a simple learn how to alternate row colors in a spreadsheet. The lessons shift into basic programming and you will have a lot of questions you won't expect unless you do it yourself first and even a second time. If you are new to GSuite put yourself out there and take the risk to do it with them. 
  • Why are you doing this work. The why is very important to students. The dreaded answer I get when we talk about why we do something is, "for a grade". That's the soul killer for all of us. Develop with your students the "Why" so it's authentic and has a real world impact. If you are doing an If-Then Story partner with another class or elementary grade and make the "Why" about developing stories for them. 


All students need digital skills. Not just in Digital Citizenship but also in Digital Production/Creation. We need to develop students that not only have content knowledge but will think beyond the facts and innovate the future. Giving students an end goal product and allowing them to select what fills it supports developing digital production skills while exploring passions. Google has provided the framework for just that. A student passionate about sports can be directed to develop an interactive spreadsheet of their favorite sports icons. Add in a map of where each player grew up. Compare players through an interactive slide deck discussing the pros and cons of each player while including comparison graphs as evidence. Wrap all this up into a website and we have a completed project which has taught a student more than just content. They’ve developed digital skills which can be applied to the workplace.

According to Bloomberg our students are most hirable when they can creatively problem-solve, communicate, think strategically, and lead. To do all this our students need to be able to Apply Digital Skills. 


Project based learning with the teacher as facilitator and differentiated delivery of instruction and assessment is a recent push in education. Don’t just talk at them, engage them in building authentic projects and even better if they have real world applications. I would even augment the previous example to suggest students interested in this subject working as a group pick an accessible local sports community team as their topic. Students become connected to an authentic audience and work with real data and information making the experience more meaningful in an ideal world.

While my experience with the Applied Digital Skills delivery platform from the teacher side hasn’t been without issue, I have found the guided activities accessible and helpful for many learners. It gives an entry point for each and works best in a classroom when all learners have access to technology on a 1-to-1 basis. It can work in grouped technology settings but some students may be left behind. I recommend weaving the units as self contained pieces through out your regular curriculum. Thank Google for helping us to develop applicable digital skills. 



Social Emotional Well-Being During Online Teaching and Learning

The world is a bit nutty right now because of the COVID-19 pandemic. Schools are switching to online learning and parents are working from...