01/05/2016 – Astronomical Weather Forecast Dev Log – 天文天气预报开发日志

前期规划日志 Previous Development Plan :

10/02/2016  & 27/02/2016


后续开发日志 Development Update:

03/05/2016


>前往中文预报页面<     >Go to the English forecast page<


以下为主要开发内容 The following is the main content:

由于公差查询器核心已经比较稳定,剩下的主要工作就是利用零碎时间完成公差数据的输入,所以开始着手完成天文天气预报。在研究清楚晴天钟天气图表API的调用方法后,开始着手研究根据访问者IP获取经纬度信息的办法。与公差查询器一样,由于我建站的空间仅支持php语言,所以天气预报页面也使用php来编写。

The core of the tolerance checker has been stable, the rest work is typing the tolerance data which can be done in spare time. I can turn to develop the astronomical weather forecast now. It’s not time-consuming to understand how to use 7Timer!’s API, then the method of obtaining coordinate by visitors’IP address must be figured out. The same reason as the tolerance checker, I choose PHP to set up the page due to my website server’s PHP environment.

为了降低初期的学习难度和开发难度,当然也考虑到测试网络环境,地理信息(IP-经纬度转换和地图)的API选用了百度而没有选用谷歌。

For decreasing the study and develop difficulties, and considering about testing web environment, Baidu Map was selected as geography API instead of Google.

首先通过

First, by using

[php]

$_SERVER["REMOTE_ADDR"]

[/php]

来获得访问者IP地址(这也造成一个问题,获取的是设备接入网络服务商时的IP,造成移动设备通过蜂窝网络接入或透过VPN访问的用户提供的IP是不准确的,造成定位错误,不能实现“本地”天气预报)

to obtain visitor’s IP (There’s problem here. Wrong IP will be fetched if the visitor is using mobile devices through cellular network or visiting the web through VPN, because the code can read the Internet service providers’ IP only)

接着将IP提交给百度地理API(可免费申请有限次数的应用,调用方法请参照百度地图API的相关手册),获取json格式的地理信息,包括地址、经纬度等。

Then hand up the IP to Baidu Map API for returning geography data including address and coordinate in json format. Baidu Map API application can be applied for free.

解码返回的地理信息并提取经纬度信息,分别提交给晴天钟的API(调用方法参见晴天钟的手册)和百度地图API,获取天气预报图表和访问者位置地图。

Decode the json and pick out the coordinate, exchange the weather chart and map image by 7Timer!’s API and Baidu Map API.

再给页面稍微美化一下,成品如图1。

Beautify the page, it works! (As Fig.1)

20160501-weatherforecast

图.1(Fig.1)


最后,再次声明利用的资源并鸣谢:

预报图表来源: 晴天钟 – 地理信息引擎: MaxMind GeoIP & 百度地图

Resources used by weather forecast and  acknowledgements

– Weather Chart Resource: 7Timer! –

– Geography Resource & API: MaxMind GeoIP & Baidu Map –

 

10/04/2016 – Plus-minus Notation Display Failure – 正负号显示问题

>Tolerance Checker Development Log – 极限偏差查询器开发日志<

最近的主要工作室录入极限偏差数据库,一直都进展的比较顺利,但是今天录入到JS/js公差带的时候遇到了一点问题,JS/js带的极限偏差是±值,一般比较便捷的记法就是±x,但是我以此格式录入的数据库最后查询出来发生了错误,显示如图1。

What I am doing recently is recording data, there was no problem until plus-minus notation display failure came out. When I met the JS/js tolerance zone, numbers are displayed  with ‘±’ ahead, which is like ±x. But the plus-minus notation became ‘?’ as Fig.1.

20160410-Plus-minus Notation Display Failure

图.1(Fig.1)

目前我猜测的可能是在查询的某个环节出了问题:

I think it must be an error at following stage:

  1. php excel reader工具不支持正负号;
  2. 字符集对正负号的支持问题;
  3. 查询器默认字体或者字体库的支持问题。
  1. php excel reader does not support plus-minus notation;
  2. character set does not support plus-minus notation;
  3. fonts of the checker/page do not support plus-minus notation.

由于这个问题无伤大雅,我暂时用比较简单的办法略过这个问题:用+/-来代替±。

Nevertheless, it is not a serious error and I decide to replace the ‘±’ with ‘+/-‘ temporarily.

 

17/03/2016 – Tolerance Checker Development Log– 极限偏差查询器开发日志

前期规划日志 Previous Development Plan :

>10/02/2016<

>08/03/2016<


后续开发日志 Development Update:

>10/04/2016<


>前往查询器 Use the checker<

以下为主要开发内容 The following is the main content:

近几日完成了查询器的主要开发工作并上线测试。

Main development work has been finished on these days, and the tolerance checker has been launched into beta test.

首先是确认了需要使用的php excel reader工具,资源来自SourceForge上的一个项目:<PHP-ExcelReader> ;调用方法参考了搜索到的这篇日志:<PHP ExcelReader用法>

First, excel reader tool has been selected. It is a SourceForge project:<PHP-ExcelReader>, and I find a Chinese user manual by this link:<PHP ExcelReader用法>

其调用方法是:

How to invoke the PHP-ExcelReader:

[php]
require_once ‘Excel/reader.php’;
$data = new Spreadsheet_Excel_Reader(); /*invoking reader*/
$data->setOutputEncoding(‘UTF-8’); /*text output encoding*/
$data->read(‘db.xls’); /*read the excel sheet*/

echo $data->sheets[0][‘cells’][i][j]; /*read the (i,j)cell
and output data*/
[/php]

这个基本结构是针对查固定路径的单个excel表格的,我先编写了一个3行3列excel表格进行测试,表单通过post形式将需要的单元格位置(i,j)将表单信息告知excel_reader,reader返回查询数据:

The basic code structure of this tool is used to read a single work sheet in one .xls file by solid path. So I created a 3*3 excel sheet for test. Html form choices with (i,j) cell position are sent to excel_reader by ‘post’ method, which would return and print out the checking result by code below.

[php]

echo $data->sheets[0][‘cells’][$_POST["row"]][$_POST["column"]];

[/php]

测试结果如图1, 成功!进入下一步开发。

Test was successful as fig.1! Next step.

20160317-checker_devlop_log-1

图.1(Fig.1)

根据日志>2<中图2的逻辑与文件结构,需要查询不同路径下不同xls的文件,路径由表单输出的数据决定,所以excel_reader读取路径处不能再填写定值,故在这之前定义了一个变量$path, 同样采取post的形式获取表单数据并编写路径,然后让reader读取$path路径:

According to logic and files structure posted on fig.2 of log >2< , the checker must visit different folders and pick out the exact .xls database file from dozens of them. In other words, the file path and the name of file should be variables. So I define a $path variable which get message from the form by post method as well. And the reader will read the $path instead of solid path.

[php]

$path="db/".$_POST["type"]."/".$_POST["zone"].".xls";

……

$data->read($path);

[/php]

由于我只在一个文件夹里存放了一个db.xls文件,当我在表单选择了一个空路径的时候或者我没有填写完所有表单项却提交了表单,reader返回了”The filename …….xls is not readable”的错误信息,我意识到整个单选表单必须填写完成才能提交。搜索了许多方法,一开始发现需要通过js等工具进行表单验证,弹出提醒框等等等。踏破铁鞋无觅处得来全不费工夫,html5直接提供了表单必填的验证,在input里添上短短一句便可:

I uploaded only one db.xls file to the database folder, then I found a problem when I select a wrong path or leave some form blank —— reader told me that ‘The filename …….xls is not readable’. And I realized I must set something for form correction. So many methods told me to use js code or else when the exactly excellent answer is so simple that you should write only 2 word in the <input>, thanks to html5 :

[html]

required="required"

[/html]

剩下的就让浏览器来做就好了,如图2

The rest of the work? Browsers will do for you as fig.2!

20160317-checker_devlop_log-2

图.2(Fig.2)

显然,如上图,我用div把表单框起来并稍微美化了一下。

Obviously, I beautified the page by <div> tag.

主要的问题都解决了,就把表单修改为正式的极限偏差查询器项目,然后上传了一个完整数据的.xls数据表,极限偏差查询器正式进入线上beta测试!

Works done and problems solved. The html form was changed into real tolerance checker type. And I uploaded the first database .xls file with useful tolerance data. It is beta test now!

20160317-checker_devlop_log-3

下一阶段的工作目标:

Plan for next version:

  1. 由于我获得的极限偏差表是纸质的,所以所有数据必须手动创建.xls文件,需要实现公差查询的基本功能,这个是主要任务也是工作量最大的任务。
  2. 学会一些CSS的内容,将查询器美化一下。
  3. 学会一些Jquery、ajax的内容,将跳转显示查询结果改为在主页刷新显示查询结果,即客户端只需要显示index,同时包含表单和查询结果显示框,表单不断复用。
  1. Tolerance data I own is on papers. If the tolerance can function as a real one, I must type the data into computer by hand and edit .xls files manually. Hard work but necessary.
  2. Learn something about CSS and use it to beatify the checker’s page.
  3. Learn something about Jquery, ajax or else. The codes can refresh the checker index page without jumping into others. Which means, the index contain the html form and the result display on same page, visitor can reuse the form and read the result on same page, without clicking “Back to index and check again”.

08/03/2016 – Tips of Tolerance Checker– 公差查询器备忘

(English version follows Chinese Part)

之前就有说过实验室板块一共打算同时进行两个项目,天文部分是晴天钟,机械部分是公差查询器。这篇文章打算记录一下公差查询器的思考内容以作备忘。

I was talking about plans of the lab before, Web Forecast for astronomy block and Tolerance Checker for mechanical block. This is the memorandum of what I have thought about building the tolerance checker.

一开始先检索了一下“检索器+数据库”结构的实现方式,包括asp+excel, php+myaql, php+excel等等等等。我根据我的客观条件,打算采用php+excel的方式来实现网页查表式的公差查询器。

The basic structure of online checker is “checker+database”, which have kinds of  method including asp+excel, php+myaql, php+excel and etc. Considering of objective conditions I have, I will go by php+excel solution.

选择php+html作为前端和服务器端的检索器是因为我已经有了一个支持php的虚拟主机,直接提供了在线调试环境,而且流量够、速度够,就不打算再倒腾一番搭建本地测试环境了。所以没有采用asp。

It is no necessary that set up another local testing environment when I have already got virtual host with php supporting. That’s why I chose php instead asp for my checker and I can test it online.

至于数据库,使用excel,是因为我完全不打算再学mysql,另一个原因是极限偏差表的数据量有点大,而且目前取得的数据必须要依靠我手工输入,所以选择excel在创建数据库的时候会比较便捷。另外,php有开源的excel读取工具可以直接调用,这对我这样一个php小白来说,实在是方便不过。

As for database, learn to use mysql may take too much time. But the core problem is that entering data of tolerance would be a huge project when I have to type it myself by hand. So, excel will be easier for me to setup database files. Luckily, php has open source of excel reader that I can use for my checker directly.

目前,参考网络上已有的php+excel查询器例子,思考了几天,打算按照如图1的结构创建查询器,不过也有可能需要更多的php文件在服务器端进行检索、查表操作。

After searching examples of php+excel checkers online, I make the structure graph as Fig.1. It is a prophase plan and there might be more php files for the checking function at server side.

20160308-tolerance_checker (2)

图1(Fig.1)

主页客户端的表单和服务器端检索的逻辑如图2,我目前最好的打算是表单和结果显示能够在同一页面展现且不断复用,这样才是“查询器”,而不是“查询页”。

The form on front page has its appearance as Fig.2 and the checking logic of server-side files have been shown as well. My better plan of the front page is that exhibiting the radio buttons and the return result on the same page which can be reused without refreshing the page.

20160308-tolerance_checker-1

图2(Fig.2)