Published Date : 2021年5月25日11:05

Part 1 - ドルと円の為替レートを使った簡単な計算アプリのアンドロイドバージョン
Part 1 - Android version of a simple calculation app that uses the dollar-yen exchange rate


This blog has an English translation


ニコニコ動画にアップした動画のまとめ記事です。

This is a summary blog post about a video I uploaded to NicoNico.

細かい部分は動画を参考にしてください。

Please refer to the video for details.


目次

Table of Contents




① 動画の説明
① Video Description



警告:

このアプリは大雑把に大体の見積りを計算して楽しむ為のツールです。

計算の詳細や、端数の処理等は各金融機関等によって異なります。

このアプリを使って何かしらの損害が発生したとしても、私は一切の責任を負いません。

Warning:

This application is used to calculate rough estimates and enjoy them.

The details of calculations and the treatment of fractions differ depending on the financial institution.

​I will not be liable for any damage caused by using this app.

ドルと円の為替レートを使った簡単な計算アプリのアンドロイドバージョンPart 1

Android version of a simple calculation app that uses the dollar-yen exchange rate Part 1

前回の動画でPythonとFlaskを使用して作成したWebアプリのアンドロイドバージョンです。

This is the Android version of the web app we created in the previous video using Python and Flask.

今回作り直すアンドロイドアプリバージョンはこのようになります。

This is the Android app version that we're going to create looks like this.


Responsive image

以前作成したPythonのWEBアプリがどのようなものだったかも見てみましょう。

Let's take a look at what a previously written Python web app looks like.


Responsive image

ではいつも通りにアンドロイドスタジオを立ち上げて、空のアクティビティを選択して、新しいプロジェクトを作成してください。

Start your Android studio as usual, select an empty activity, and create a new project.

まずCSVファイルの読み込みとデータの操作を行うクラスファイルを作成します。

First, create a class file to read the CSV file and manipulate the data.

import android.content.Context;
import android.content.res.AssetManager;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CsvDriver {

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    public void csvReader(Context context) {

        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

次に購入と売却の取引の為のクラスファイルを作成します。

Next, create a class file for the purchase and sale transactions.

import java.util.ArrayList;
import java.util.List;

public class Transactions {

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

次にいつもどおりに電卓のアクティビティとそのレイアウトファイルを同時に作成します。

Next, create the Calculator activity and its layout file at the same time, as usual.

次にいつもどおりにボーダーXMLファイルをdrawableフォルダ内に作成します。

Next, create the border XML file in the drawable folder as usual.

次に購入取引の結果を表示するためのレイアウトファイルをresフォルダ内に作成します。

Next, you create a layout file that displays the results of the purchase transaction in the res folder.

次に売却取引の結果を表示するためのレイアウトファイルをresフォルダ内に作成します。

You then create a layout file in the res folder to display the results of the sale transaction.

最後にCSVファイルを格納する為のassetsフォルダを作成します。

Finally, create an assets folder to store the CSV file.

前回のPythonとFlaskを使ったWEBアプリで使用したCSVファイルを、先ほど作成したassetsフォルダ内にコピペします。

Copy and paste the CSV file you used in the previous Python and Flask web app into the assets folder you just created.

しかし、前回使用したCSVファイルは2002年の4月以降のデータしかありませんでした。

However, the CSV file I used last time had only data after April 2002.

なので、2002年の3月以前のデータと2020年の12月のデータを付け加えていきます。

So I will add the data before March 2002 and the data in December 2020.

まずはCSVファイルがあるフォルダ内でSHIFTキーを押しながらマウスの右クリックをします。

First, in the folder containing the CSV file, hold down the SHIFT key and right-click the mouse.

そして、[PowerShellウィンドウをここで開く]を選択します。

You then select [Open PowerShell Window Here].

IPythonコンソールを立ち上げて、PythonとPandasを使ってCSVファイルの中身をもう一度整理していきます。

Launch the IPython console and use Python and Pandas to reorganize the contents of the CSV file.

CSVファイルを読み込むためファイル名をコピペします。

Copy and paste the file name to import the CSV file.

そしてpandasのread_csvメソッドの引数にファイル名とエンコーディングにshift_jisを指定してCSVファイルを読み込み、データフレームに直します。

Then, a file name is designated as an argument of the read_csv method of pandas, and shift_jis is specified for encoding method to read a CSV file and convert it into a data frame.

前回の時と同様にpandasのto_datetimeメソッドを使って日付の列をdatetimeオブジェクトに直します。

Use the to_datetime method of pandas to convert the date column to a datetime object, as before.

表示されている文字が少し小さいので、PowerShellウィンドウのオプションを使って表示される文字を大きくします。

Because the characters displayed are slightly smaller, use the options in the PowerShell window to make the characters displayed larger.

データフレームの列をdatetimeオブジェクトに直せば、年や月や日毎に値を取り出すことができるので便利です。

It is useful to turn a column of a data frame into a datetime object so that values can be retrieved for each year, month, or day.

データフレームに対してilocやlocを使うことで、インデックス番号とスライスや列名を用いて指定した行や列の値を取り出すことができます。

Using iloc or loc on a data frame, you can retrieve the value of a specified row or column using the index number and slice or column name.

パート2へ続く。

Continue to Part 2.



以上です。お疲れ様です。

That's all. Thank you for your hard work.