2016年9月24日星期六

Week9 display orb functions

In this weekwe start working on the display aspect. The original idea is display orbs on the home page by using different color based on the emotion, also when user point to the orb, then will display preview image on the orb.

For display orbs function, there are two steps. Firstly, we have to use PHP to get the data from database, the function includes connect database and get the data by using SQL.

 
database connection & SQL

Secondly, we use JavaScript to display these orbs on the homepage, and we want place orbs into shelves randomly. So we designed a process method for this function. We create a random number generator, then store each orb into an array (taken_orbs[ ]) with a unique random number ID. Because we initially display every orb within each shelve, then we want to display the same number of orbs with database, so we create another array include all orbs IDorbs_to_hide[ ], match random number ID and orbs ID, hide the orb which not include in the first array (taken_orbs[ ]). In order to hide the orbs, we using jQuery to manipulate orb CSS opacity to 0.          

store orb data into array & assign unique random number to each orb






Create orbs_to_hide array & compare two arrays

hide the orbs

The next step is display orbs with different emotion by using different color, so we get each orb emotion (stored in database when create a new orb), then we use JavaScript function to compare the emotion, If the stored emotion is same with the function emotion, then use jQuery to change the CSS color.  

compare emotions
In order to display preview image when user point to the orb, we use jQuery to detect user action and then add image URL to the orb.   

 
display image when "hover"
Moreover, we discussed about the search function and login function, the result is that we don’t need these functions, because we can create a “my orb” page to display several recent created orbs, and make the latest created orb to be a special orb, then user can know which one is his orb.
  
we also want to make the latest created orb display in different way, so we use another PHP to access database and use SQL language to get the maximum orb id (which is the latest orb ID), then use JavaScript and jQuery to display that orb in special way. 
display latest orb in different way

Week8 Flow & Back-end functions

In this week, I start build the back end functions, include “add a dream” function and “View a dream” function. For “add a dream” interactions, there are six steps, 1. User clicks icon and go to the “add a dream” page (build into the front end) 2. User types out dream story and selects the emotion. 3. User click “next” button go to the next page 4. User types keyword associated with dream for images. 5. Trove adds two images related to the keyword 6. Users can change images by clicking the refresh button 7. User drags the orb to the chute to save dream to the database.

For the front end aspect, all icons and buttons were created by using HTML and CSS. For the back end aspect, there actually are three steps, 1. connect to Trove and get images from Trove 2. Manipulate (refresh function) Trove images and other data (story, orb ID, emotion), 3. store data to the database.

Firstly, I follow the Trove API Technical Guide to build Trove connection by using JavaScript. I create several variables to get user input values (keyword) and API key, then create a search query same with the Trove API Technical Guide: http://api.trove.nla.gov.au/result?key=<INSERT KEY>&zone=<ZONE NAME>&q=<YOUR SEARCH TERMS> [1]. Then I use “getJSON”method to get the JSON information we need to display the images.

Search from Trove
 
getJSON method & Random number generator

When I extend the JASON data, I found that each image contains two different URLs, one URL link type is “fulltext” and another one is “thumbnail”. The different of these two URL is that we can directly use “thumbnail”URL to display image content, but the image quality is very low, but we can’t directly use “fulltext” URL without get permission from other website, such as Flickr. In order to get the high quality images, I was inspired by one Trove example which is “Images & Trove” [2], it’s show us how to reformat and access high quality images from each website ("flickr.com", "nla.gov.au", "artsearch.nga.gov.au", "recordsearch.naa.gov.au", "images.slsa.sa.gov.au").  
 
Reformat URL

Access Flickr by using Flickr key

Secondly, the original idea is that display two images and user can refresh each image. I create two variables that contain random number, because image URL stored in an array, so using these random numbers, then we can display two random images after user search from Trove, and two images URL will store into two variables, they will become the image path and stored into database. Then if user click refresh button, then generate a new random number and display the correspond image from array, also update two image path variables.  But there is a potential problem which is generate two same random numbers, but we don’t want to show users two same images at same time. So I added one function to prevent this issue, the function triggered if two random number is same, then it will change one random number to avoid duplication.

After user click refresh button & prevent duplicate function

Display two images

Update URL after user click refresh
Thirdly, in order to store orb information, we were using PHP to connect to the database, then use SQL to manipulate the orb data, such as update and insert. There are two steps for store dream content, 1. Generate a orbID, the first orbID is 0, the second orbID will be the above orbID plus one, and so on, the function is that getting the max orbID in the database, and adding one in order to create the next orb ID for this new orb, then we can make sure there is no duplication (primary key). 2. Insert orbID, Story, Emotion, image1URL and image2URL to the database, but the imageURL is NULL value, because the story and emotion come from different web page, so we want to add orb first, then update the image URL after user finish the selection. 3. Update two orb image path. 

connect to the database

Generate unique orb ID

Insert a new orb into database
Update two image path URL

For this week back end codingwe have considered the flow in web. We keep the maximize efficiency for every functions, because back end has logic complexity, if the function too complex and take more times to finish the job, the performance issues can negatively impact the user's experience. We improve many times for each function, so that they can get the result efficiently.  

We also set clear goals for each function, because every function has a significant purpose, if the goals not clear, it’s may cost overwrite or errors. For example, when we built the random number generator, we only considered matches two numbers with loaded image array, so we create two generators for each image, then we got duplication issue, so actually the goal of this generator is to generate two different numbers, which need a function to avoid the duplication.

References :

[1] Trove API Technical Guide

Source: http://help.nla.gov.au/trove/building-with-trove/api-technical-guide


[2]Getting High Quality Images

Source: http://deco1800.uqcloud.net/examples/troveImage.php


2016年9月9日星期五

Week7 MVC & Database design

In this week lecture, we were discussed about various of patterns, these patterns are useful when generate repeatable solutions to commonly occurring problems in software design. There is a very important pattern which is model-view-controller is highly related for our concept back end design.

Models represent knowledge, a model could be a single object, or it could be some structure of objects, so the model for our concept is the database structure, which include adding and retrieving items from DB, processing data from/to the DB and only connect to the controller. The view is a representation of the model, in our case, it’s the client side or front end, which include HTML and CSS, also the browser. The view also speaks only with the controller. A controller is the link between a user and the system, it can processes GET/POST/PUT/DESTROY requests (by using PHP) and handle all other server-side logic. The processes steps are 1. takes information from user 2. processes information and talks to the database if needed 3. Receives information from database 4. Speaks to view to explain presentation to the viewer (how display data to the screen).

Our concept back end is similar with model-view-controller pattern. When user want to view a dream, after he click the dream icon, then a request sends to the controller, PHP will access the database, then process the request and get the data, controller then send the data to the font end, the dream detail shows on the screen with an appropriate format and layout.

 
MVC




For our concept database design, firstly, I create a relational schema to define each table and their relationships. According to our original concept, there are three tables, the first table is “orb”, it includes two attributes which are orb ID and dream description, another table is “image”, also include two attributes which are image ID and image URL, the third table is “emotion”, it consists of emotions and emotion ID. There are two relationships, the first relation is: an orb must have two images, an image may be used by many orbs. The second relation is: each orb must have one emotion, and each emotion may belong to many orb.  


Relational Schema


Tables in phpmyadmin 

For the data type, I set all IDs as INT type, because they are numbers, so integer is a better choice.  I also set other attributes as VARCHAR type, because VARCHAR represent character string.

Primary keys: orb ID, image ID, motion ID
Foreign key: Table “Orb” (image ID) --à Table “image” (image ID)  , this may change after relational Mapping, because it’s M:N relationship
           Table  “Orb”(Eid) --à Table “emotion” (Eid)

Emotion table structure
Image table structure
Orb table structure
Relationships


2016年9月2日星期五

Week 6 Task flow & Interaction map & Prototyping

Task flow

In this week, my team finalized first stage of concept design and defined our implementation scope and project plan.  But when I try to create an interaction map for explain our concept functions and interactivity, I found that there were some unclear areas between user interaction and interface, so I discussed with another team member who is also the original concept creator. We create a high level task flow to help my team to understand more clearly about the concept by shows the main form of interaction and functions.


high-level task flow


In conclusion, the main form of interactivity includes creating, publishing dreams and viewing, exploring dreams. For creating and publishing dreams, user can select from dynamic images viewing and exploring dreams. The user action includes click buttons, 
drag the orb.

Interaction map & Prototyping 

According to the lecture, I think the next important step is prototyping, prototype can help us evaluate designs, because we still not sure how to implement several functions. I also think solve some design problems before getting deep into coding is an efficient way for saving effort and time. Before start prototyping, we need visualizing the concept interactions, so I create two interaction maps combine with storyboard (two scenarios) and user interactions.

In the interaction map, I insert some storyboard scenes before show the application interfaces, because they can provide scenarios that users might encounter when using the application that can help people understand the purpose of our concept and potential target users. Then I create all interface that required by concept, some gestures added on the interface to help people to understand user interactions of each operation. The interact flow is the same as high-level task flow.

Interaction map & Storyboard & Tasks


Interaction map & Storyboard & Tasks