使用Pandas和matplotlib库进行简单的数据分析与可视化

Introduction

Pandas 是 Python 语言的一个扩展程序库,用于数据分析。

Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. Matplotlib makes easy things easy and hard things possible.

本文章将会对一些数据data.csv进行处理与绘图,形如:

Idx Title of Book Description Authors Rating Price Availability Book Category
0 It’s Only the Himalayas Wherever you go, whatever you do, just . . . don’t do anything stupid. S. Bedford 2 45.17 19 Travel

Analysis

Read File

利用pd.read_csv完成读取,指定index_col字段,以指定数据随后所使用的索引。

1
2
3
4
5
import matplotlib.pyplot as plt
import pandas as pd
pd.set_option('display.width', 500)
pd.set_option('display.max_columns', 100)
dfcand=pd.read_csv("data.csv", sep=',',index_col=0)

Group by

dataframe对象使用.groupby()可以对数据进行合理的归并分组,是一个pandas.core.groupby.generic.DataFrameGroupBy 对象

.size()

.size()字段可以得出各个分组的名称和对应大小(数量),是一个pandas.core.series.Series对象

1
2
3
4
5
6
7
8
9
10
11
12
dfcand.groupby('Book Category').size()

#Book Category
#Academic 1
#Add a comment 67
#Adult Fiction 1
#Art 8
#Autobiography 9
#Biography 5
#...
#Young Adult 54
#dtype: int64

Series对象

.sort_values(ascending=False)

Series对象,.sout_values()可以规定其排序方式

1
2
3
4
5
6
7
8
9
10
11
12
piedata = dfcand.groupby('Book Category').size().sort_values(ascending=False)

#Book Category
#Default 152
#Nonfiction 110
#Sequential Art 75
#Add a comment 67
#Fiction 65
#Young Adult 54
#...
#Academic 1
#dtype: int64

一般的,对于Series对象,可以利用比较符号进行筛选,例如,我们要获得以上大于7的值

1
2
3
4
5
6
7
8
abovepiedata = piedata[piedata>7]

#Book Category
#Default 152
#Nonfiction 110
#...
#Autobiography 9
#dtype: int64

pd.concat()

可以使用此方法将多个Series对象合成为dataframe对象

当axis = 1时,如果其索引一样,会将合并的Series作为新的列,最终合并为dataframe

1
pd3d = pd.concat([ratingseries,availabilityseries,sizeseries],axis= 1,ignore_index= False)

对于合并后可能出现的未命名列,可以使用.iloc 获取,例如

1
pd3d.iloc[:,2]

Benford

By Benford’s law it is often the case that 1 occurs more frequently than 2, 2 more frequently than 3, and so on. This observation is a simplified version of Benford’s law. More precisely, the law gives a prediction of the frequency of leading digits using base-10 logarithms that predicts specific frequencies which decrease as the digits increase from 1 to 9.

1
2
3
4
frequency = {'1':0,'2':0,'3':0,'4':0,'5':0,'6':0,'7':0,'8':0,'9':0}
def benford(num):
firstdigit = str(num)[0]
frequency[firstdigit] = frequency[firstdigit] + 1

Draw diagrams

General

1
2
3
4
5
6
7
8
9
plt.figure(figure = (10,10) #规定画布的大小
plt.rcParams.update({'font.family': 'Times New Roman'}) #规定显示字体
plt.rcParams.update({'font.weight': 'normal'}) #规定字体粗细
plt.rcParams.update({'font.size': 15}) #规定字体字号

#Draw Diagram

plt.title("This is a figure") #规定图片标题
plt.show() #显示图片

Pie

Series对象,可利用.values获取其值

利用plt.pie()绘制饼图

第一个参数提供数据

labels = 提供对应数据的标签

startangle = 规定第一个刻度的角度27a6d1f0aa648134a54357c580480631.png

labeldistance = 规定标签到饼图的距离

1
plt.pie(abovepiedata.values,labels=abovepiedata.index,startangle= 32,labeldistance= 1.12)

3D Scatter

1
2
3
4
5
6
7
ax = plt.axes(projection = '3d') #规定为3D散点图
ax.scatter3D(pd3d['Rating'], pd3d.iloc[:,2], pd3d['Availability']) #为散点图提供数据
plt.xticks((range(5)) #规定x轴的刻度标度

plt.xlabel('Avg Rating')#规定x轴标签
plt.ylabel('Size of Category',rotation = 39)#规定y轴标签
ax.set_zlabel('Avg stock')#规定z轴标签

60be8e80839f1377b500f8880e84589a.png

Bar & Plot

plt.bar() 中,x = 提供了数据的条目(有几列数据)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
plt.bar(x=range(len(benser)), height=benser, label='Data', tick_label = benser.index)

plt.xlabel("First Digit")
plt.ylabel("Data")

#与上图共用同一个x轴
ax2 = plt.twinx()

#规定y轴的取值区间
ax2.set_ylim([0.04, 0.33]);
plt.plot(range(len(benser)), y, marker='.', color ='goldenrod', linewidth='1', label="Benford's Law")

#给出折线上的百分比图例
plt.legend(loc="upper right")
for a, b in zip(range(len(benser)), y):
plt.text(a, b, str('{:.2f}'.format(b*100)) + '%', ha='center', va='bottom', fontsize=8)

31c32aecc6b84bc4f1c38402c0cfb495.png

How to get the author of the book by title

Introduction

思路很简单,找到一个 API 即可。

此 API 接受书名(Title)作为参数,返回的数据中须包含作者(Author)字段。

经过一些探索,Google Books APIs 可以作为一个合格的解决办法。而Goodreads.com的搜索框可以是一个辅助选项。

Google Books APIs

Refer to this webpage to find more information: Google Books APIs Getting Started

Google Books has a vision to digitize the world’s books. You can use the Google Books API to search content, organize an authenticated user’s personal library and modify it as well.

Books concepts

为了能够正确处理随后返回的json数据,应当理解以下四则基本概念:

  • Volume: A volume represents the data that Google Books hosts about a book or magazine. It is the primary resource in the Books API. All other resources in this API either contain or annotate a volume.

  • Bookshelf: A bookshelf is a collection of volumes. Google Books provides a set of predefined bookshelves for each user, some of which are completely managed by the user, some of which are automatically filled in based on user’s activity, and some of which are mixed. Users can create, modify or delete other bookshelves, which are always filled with volumes manually. Bookshelves can be made private or public by the user.

    Note: Creating and deleting bookshelves as well as modifying privacy settings on bookshelves can currently only be done through the Google Books site.

  • Review: A review of a volume is a combination of a star rating and/or text. A user can submit one review per volume. Reviews are also available from outside sources and are attributed appropriately.

  • Reading Position: A reading position indicates the last read position in a volume for a user. A user can only have one reading position per volume. If the user has not opened that volume before, then the reading position does not exist. The reading position can store detailed position information down to the resolution of a word. This information is always private to the user.

Working with volumes

You can perform a volumes search by sending an HTTP GET request to the following URI:

https://www.googleapis.com/books/v1/volumes?q=search+terms

例如:搜索书目《It’s Only the Himalayas》,如果配置正确,会得到一个json,内含所有的搜索结果,一般的,认为第一个结果就是我们搜索得到的书目。

Goodreads.com

Refer to this webpage to find more information: Goodreads.com

Discover and share books you love on Goodreads, the world’s largest site for readers and book recommendations!

实例请求:搜索《Test》

对于搜索请求https://www.goodreads.com/search?q=`keyword`&qid=

只需要将关键词填入q=后

Scrape

Goodreads.com 可能有反爬机制,可以使用伪装浏览器的办法缓解一些情况:

1
2
3
4
5
6
7
8
send_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36",
"Connection": "keep-alive",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.8"
}

result = requests.get(main_url, send_headers, proxies=proxies)

一些情况下Goodreads也无法给出正确的作者,需要使用try catch关键字捕获异常情况。

Python Code

注意事项

对于在Python中使用这两个办法,需要注意一些内容

  1. 代理可能导致错误request eof occurred in violation of protocol (_ssl.c:997)

    多见于使用的代理工具代理模式为全局代理,并且未在Python脚本中正确配置代理,尝试通过以下办法解决:

    1
    2
    3
    4
    5
    6
    7
    8
    import requests
    proxies = {
    'http': 'http://your_server:your_port',
    'https': 'http://your_server:your_port',
    }

    #仅在需要代理的请求下,填写参数proxies=proxies
    result = requests.get(Full_API_Link,proxies = proxies)
  2. Google Books APIs 所返回的json中,结果title字段下的标题并不与本地title字段相匹配。通过使用Python自带的 difflib 库实现匹配功能。

  3. 由于持续的请求,可能会导致请求失败,故使用try: except:关键字捕获异常,保证程序正常运行。

简单实现

假设:

  1. 本电脑使用的代理工具是CFW,未开启全局代理,默认端口

  2. 可以正常请求到对应书目,遍历json找到最为匹配的标题。

  3. Google Books APIs 无法正确获得作者,进而使用Goodreads尝试获取之。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import requests
proxies = {
'http': 'http://localhost:7890',
'https': 'http://localhost:7890',
}
import json
import difflib、
from bs4 import BeautifulSoup

def UrlToSoupAdvanced(Url:str):
main_url = Url
print(main_url)
send_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36",
"Connection": "keep-alive",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.8"
}

try:
result = requests.get(main_url, send_headers, proxies=proxies)
except :
time.sleep(5)
return "[Unknown][Goodreads]Fail to request the link"

return BeautifulSoup(result.text, 'html.parser')

def TwoStrMatch(string1:str,string2:str):
result = difflib.SequenceMatcher(None, string1, string2).quick_ratio()
print(string1 + "====" + string2 + "====" + str(result))
return result

def GetAuthorByTitleUsingGoogleBooksAPI(Title:str):
Google_Book_APIs_Head = "https://www.googleapis.com/books/v1/volumes?q="
API_KEY = "AIzaSyCdlpdS8EWgKIN6EW95fwjiLqDkkiIA8Pg"
Search_Data = Title

#https://www.googleapis.com/books/v1/volumes?q=A%20Summer%20In%20Europe+intitle:keyes&key=AIzaSyCdlpdS8EWgKIN6EW95fwjiLqDkkiIA8Pg
#https://www.googleapis.com/books/v1/volumes?q=a summer in europe&printType=books&intitle:a summer in europe

Full_API_Link = Google_Book_APIs_Head + Search_Data
#Full_API_Link = Google_Book_APIs_Head + "It's_Only_the_Himalayas"

print("The request link is " + Full_API_Link)
try:
result = requests.get(Full_API_Link,proxies = proxies)
except :
time.sleep(5)
return GetAuthorByTitleUsingGoodreadsSearch(Title)



return_json_dict = json.loads(s = result.text)
if 'items' in return_json_dict:
return_items = return_json_dict['items']
else:
return GetAuthorByTitleUsingGoodreadsSearch(Title)

#对于返回的搜索结果
for book in return_items:
current_volumn = book['volumeInfo']
current_title = current_volumn['title']

if 'authors' in current_volumn:
current_authors = current_volumn['authors']

#如果标题直接匹配,正常返回
if (TwoStrMatch(current_title, Title) > 0.85):
return str(','.join(current_authors))

if('subtitle' in current_volumn):
#如果加上副标题是匹配的,则正常返回
if (TwoStrMatch(current_title + current_volumn['subtitle'], Title) > 0.85):
return str(','.join(current_authors))

return GetAuthorByTitleUsingGoodreadsSearch(Title)

def GetAuthorByTitleUsingGoodreadsSearch(Title:str):

Full_Search_Link = "https://www.goodreads.com/search?q=" + title +"&qid="


try:
soup = UrlToSoupAdvanced(Full_Search_Link)
except:
return "[Unknown][Goodreads]Fail to request the link"

try:
author = soup.find('span', itemprop="author").div.a.span.string
except:
return "[Unknown][Goodreads]No correct Author"

if(author == None):
return "[Unknown][Goodreads]No correct Author"
return author

Camera

Introduction

参考视频:# 04.相机系统 | GAMES204-计算成像

Nautilus Eye 大王乌贼 小孔成像阶段

tapetum incidum 反射层,提高夜视能力

Compound Eye 光场相机

Human Eye

Visual acuity: 20/20 is ~1 arc min

Field of view: ~190° monocular, ~120°binocular,~135° vertical

Temporal resolution: ~60Hz(depends on contrast, luminance)

Dynamic range: instantaneouse 6.5 f-stops,adapt to 46.5f-stops

Color: everything in the CIE xy diagram; distances are linear in CIE Lab

Depth cues in 3D displays: vergence, focus, conflicts,

Accommodation range: ~8cm to ∞,年龄越大看看近能力越差

Camera Optics: Lens

ec646e532214e77599a4bcecd23f81be.png

a8047fc3ad676d0b026095db6b8b5f19.png

Aberrations

Distortion

2022-09-28-15-40-12-image.png

Aperture

2022-09-28-15-41-50-image.png

2022-09-28-15-45-18-image.png

Unit: f-number N = f/D

f 焦距,D aperture 直径

D 越小,进光量越大,景深越小

Camera Depth of Field

物距、Aperture Size、放大率

M放大率越大,景深越小

25ee6b05eabc4a82a38d73a3428931e0.png

2022-09-28-15-47-03-image.png

hyper plane

b6ea4cceb87c62e7a74dbe0e4b696757.png

光圈小会带来曝光时间长的问题

Field of View

超广角,长焦

824cb200b298e4cb4590c2af2ed6e4f3.png

Focal length 是固定的,Sensor 是固定的

f27778e65d026159398b0d7e87ab3c4f.png

a6b225fadce5b51fe63034a26bc7c05b.png

Diffraction Limit 衍射极限

5f726342e3625ca0ba111aefc6212dea.png

Dolly zoom

Sensor 传感器

非线性的 曝光程度(Log Exposure)和曝光密度(Density)

84dd9d32bb15d0ac9e3fa0475dedca08.png

HDR imaging 高动态范围

ac9925536f0387a309d0128aac782576.png

415bf0d42c896f3e46f1a614d4403756.png

ISO 相对线性
5375eb11736d57918a6387a4a0c5da08.png
电子快门对于运动快的物体会导致拉伸变形

Intro to Android

Application Components

Services

A service is an component that runs at the background

E.g. music play at the background

Service is not a thread

Broadcast Receiver

Receives broadcast from Android system and other apps and responses with pre-coded actions.

Apps are required to regist to get the broadcast

Example: When the battery level changes, the system broadcast a message.

Activity

Offen refer to one interface on your phone.

Primary class for interacting with user.

For example, Wechat:

  • When you click on the app launcher, its corresponding greeting page
    will be shown to you.

    Android system invokes the main activity of the Wechat.

  • Apps that request for online payment (such as railway ticket
    payment) can directly reach the payment page.

    Another app invokes the payment activity of Wechat.

  • Apps that request for “share on moments” can directly invoke the
    moments sharing page of Wechat.

    Another app invokes the “share on moments” activity of Wechat

Back Stack

When a new activty is launched, the previous activity will be paused and sent to the top of the back stack

3074c66675d6c28231d50f91cb67a2ae.png

Life circle

  • Runing: The activity is on the top of the screen and gained focus. Running will not be killed.

  • Paused: The activity is on the top of the screen and gained focus.

  • Stopped: The activity is completely covered by another running activity.

  • Destroyed

When running short of memory, a stopped activity is more likely to get killed than a paused/running activity.

5f74b1146359b2da39a899a5156f07a6.png

Good implementation of callback functions can make your app more robust and performant.

Possible issues with a bad implementation:

  • Crashing if the user receives a phone call or switches to another app while using your app.

  • Consuming valuable system resources when the user is not actively using it.

  • Losing the user’s progress if they leave your app and return to it at a later time.

  • Crashing or losing the user’s progress when the screen rotates between landscape and portrait orientation.

CallBack Funtions: Typical Uses
  • onCreate(): Initial setup, load persistent state.

  • onRestart(): read cached state

  • onStart(): reset application

  • onResume(): start foreground-only behaviors

  • onPause(): shutdown foreground-only behaviors

  • For example: temporarily stop UI animations.

  • onStop(): cache state

  • onDestroy(): save persistent state

The above points are very general. Carefully design your app and keep the life cycle graph in mind.

Create Activities

23c0e5afcf14c33b320504479143645f.png

  1. Create a new Activity class. Which either inherits Android.app.Activity or its subclasses.

  2. Override Activity.onCreate().

  3. Create a layout XML file in res/layout and use setContentView() to load this layout.

  4. Register the new activity in AndroidManifest.xml.

    If it is a main activity, you need to add a special section in the manifest file.

    5f50cb9f027a1bd432f0dc1ea3bb051c.png

Activities can be started by calling the function

1
startActivity(Intent intent)

To call Activity2 Inside an activity, do:

1
2
3
4
Intent intent =
new Intent(this, Activity2.class);

startActivity(intent);

The name of the target activity is not always explicitly specified. For instance, to let Android system choose an suitable activity for sending email (in Lecture 9):

1
2
3
Intent intent = new Intent(Intent.ACTION_SEND);
Intent.putExtra(Intent.EXTRA_EMAIL, recipientArray);
startActivity(intent);

Obtain vals from another activity

Sometimes we wish to obtain results from another activity. We need to start the activity using

1
startActivityForResult()

You must also implement the function below to get the return result

1
onActivityResult()

e3abb411a93727fb5764515c2ad064d3.png

Closing Activities

Android will automatically manage the life cycles of your activities.

You can destroy the current activity manually by calling finish().

To finish an activity that you previously invoked with

1
2
startActivityForResult(Intent,
int), use finishActivity(int requestCode)

Can be handy when you want to make sure that the user won’t return to this activity in the future.

Passing Data between Activities

f7362876239d8ffc3874022bfed42ee0.png

Bundle and Intent is actually the same thing.

Console output

Your console output (System.out) can be seen from the “run” window in Android Studio.

You should normally use Log class instead, though:

Android Logcat | Log.v(), Log.d(), Log.i(), Log.w(), Log.e() - EyeHunts

Install Anaconda & Jupyter Notebook

0. Intro

Anaconda offers the easiest way to perform Python/R data science and machine learning on a single machine.

Jupyter Notebook is the original web application for creating and sharing computational documents.

More information related to this topic could be found from:Installing Python · cs109/content Wiki · GitHub

1. Install Anaconda

官网下载链接:Anaconda | Anaconda Distribution

For Windows user:

  1. 点击绿色按钮即可下载,若下载速度过慢,可以考虑镜像清华大学开源软件镜像站 | Tsinghua Open Source Mirror,或右键使用迅雷下载。
    c61a4a5e9ff2e264b7a7a4a4e0289ad9.png

  2. 下载完毕后打开安装包,一路next默认同意即可。安装进度条走完需要约五到六分钟。

  3. 安装成功后,打开开始菜单(win+s)→搜索Anaconda,打开。
    e9559ebb95e08a8d87c1d6b8e5b52ee7.png

  4. 一般首次启动时间较长,有时会提示更新,安装更新即可。

  5. 启动 Jupyter Notebookd31359c5234f7109b9819b59c01f0f46.png

  6. 正常情况下浏览器打开,可以看到所在目录

    77e23a5cd60e6fd6715d0442d68ed9dc.png

  7. .ipynb文件添加到该目录下,点击即可在浏览器中打开。

Install Libraries

a379d50d6d045afbb61b641f41d972d7.png

Change the working directory

如果未生成过 Jupyter 的配置文件jupyter_notebook_config.py
打开 Anaconda Prompt
026c47fcb4a58e006629a22f4fa4fb3c.png
输入

jupyter notebook --generate-config

配置文件生成在了对应路径下,即C:\Users\xiaonan\.jupyter

打开此配置文件,找到c.NotebookApp.notebook_dir字段,等号右边填入需要变更为的目标路径
c.NotebookApp.notebook_dir = "D:\XJTLU\INT303\Labs",并去除行前的注释#

重新打开Jupyter Notebook 即可。

Configure Git to use a proxy

Configure Git to use a proxy

为git配置socks5代理

git config --global https.proxy 'socks5://127.0.0.1:7890'

为git配置http代理

git config --global http.proxy http://@127.0.0.1:7890

展示已配置的代理:

git config --global --get-regexp http.*

参考教程
https://gist.github.com/evantoli/f8c23a37eb3558ab8765

In Brief

You may need to configure a proxy server if you’re having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port 

Or for a specific domain, something like:

git config --global http.https://domain.com.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
git config --global http.https://domain.com.sslVerify false 

Setting http.<url>.sslVerify to false may help you quickly get going if your workplace employs man-in-the-middle HTTPS proxying. Longer term, you could get the root CA that they are applying to the certificate chain and specify it with either http.sslCAInfo or http.sslCAPath.

See also the git-config documentation, especially the following sections if you’re having HTTPS/SSL issues

  • http.sslVerify
  • http.sslCAInfo
  • http.sslCAPath
  • http.sslCert
  • http.sslKey
  • http.sslCertPasswordProtected

In Detail

Configure the proxy

You can configure these globally in your user ~/.gitconfig file using the --global switch, or local to a repository in its .git/config file.

Setting a global proxy

Configure a global proxy if all access to all repos require this proxy

git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port 

URL specific proxy

If you wish to specify that a proxy should be used for just some URLs that specify the URL as a git config subsection using http.<url>.key notation:

git config --global http.https://domain.com.proxy http://proxyUsername:proxyPassword@proxy.server.com:port 

Which will result in the following in the ~/.gitconfig file:

[http]
[http "https://domain.com"]
    proxy = http://proxyUsername:proxyPassword@proxy.server.com:port 

Handle subsequent SSL protocol errors

If you’re still having trouble cloning or fetching and are now getting an unable to access 'https://...': Unknown SSL protocol error in connection to ...:443 then you may decide to switch off SSL verification for the single operation by using the -c http.sslVerify=false option

git -c http.sslVerify=false clone https://domain.com/path/to/git 

Once cloned, you may decide set this for just this cloned repository’s .git/config by doing. Notice the absence of the --global

git config http.sslVerify false 

If you choose to make it global then limit it to a URL using the http.<url>.sslVerify notation:

git config --global http.https://domain.com.sslVerify false 

Which will result in the following in the ~/.gitconfig file:

[http]
[http "https://domain.com"]
    proxy = http://proxyUsername:proxyPassword@proxy.server.com:port
    sslVerify = false 

Show current configuration

To show the current configuration of all http sections

git config --global --get-regexp http.* 

If you are in a locally cloned repository folder then you drop the --global and see all current config:

git config --get-regexp http.* 

Unset a proxy or SSL verification

Use the --unset flag to remove configuration being specific about the property – for example whether it was http.proxy or http.<url>.proxy. Consider using any of the following:

git config --global --unset http.proxy
git config --global --unset http.https://domain.com.proxy

git config --global --unset http.sslVerify
git config --global --unset http.https://domain.com.sslVerify 

微信开发者工具 版本管理 Azure Repo

通过ssh连接

生成ssh密钥
Windows Platform:
win+r键调出“运行”
输入cmd调出命令行
48510d187dc59f447bc4576b16cbdc40.png
输入
ssh-keygen -t rsa -C "xiaonan.pan"
-t rsa 表示采用 rsa 算法
-C “xiaonan.pan” 表示注释
93734751351e9e13ff5a9db7e727f0fb.png
键入 密钥保存的路径(一般照抄即可)

在给定的文件夹C:\Users\xiaon.ssh下,我们看到
3188872e89a0089a9e20ddb437a3db8b.png
id_rsa.pub即为公钥内容
选择记事本打开之
复制其中所有的内容,填写到GitHub的Key中
6e9553c6216f84d144054c9df2d1054a.png
a4622b799add66b0752bb413dcc9d20b.png
单击Add SSH key

Ubuntu Platform:
在终端输入
ssh-keygen -t rsa -C "xiaonan.pan"
后续步骤如上。

.ssh保存在 ~/.ssh/下
65f9496157f9c72ff0fe04d1a9e44871.png
利用
vim id_rsa.pub 
打开复制公钥,上传
在使用 git 命令行时注意使用SSH连接:
git clone git@ssh.dev.azure.com:v3/CPT202-GroupA-8/Maplus/Maplus

id_rsa 即为 rsa私钥,须保密保存
id_rsa 即为 rsa公钥,上传到Azure SSH key 管理页面

cd38127dc8ece3f586c3661d26454726.png

d742570eb34beadbc1a7d23a695f2eca.png

右下角确认add

随后配置微信开发者工具的版本管理
3faa4792f246fac391c044660e27dea5.png
设置

网络和认证改为
b208d48255ed44e6210876e95ef5871a.png
密码口令是刚刚 ssh生产中 passphase 的内容,此处我并没有设置passphase,故留空。

c7172f79cbb2e37242715dd38a7bbb9c.png
配置远程代码仓库

754df68baa544e476739a2aca73b0d43.png
URL填入SSH地址
16416134d217416dec23007b84a0d82d.png
804c0715c6d2f7922fa436fbd89e5fa7.png

配置完成。

Memory Management

为什么要有逻辑地址的概念?
程序是给定的,硬件可用的地址是变化的。
所以需要引入逻辑地址的概念,做逻辑地址与物理地址的映射。

如何映射?

固定偏移量映射
缺陷:

  1. 一个进程使用的最大内存量是变化的。
  2. 分配的内存的利用效率不高,内碎片
  3. 外碎片

分页
程序逻辑内存分为多个页(page)
物理内存分为多个帧(page frame)
一个内存地址处存储的内容 为一个字节, 1B
利用页表(Page Table) 存储二者的对应关系
页号,帧号,当前这一条目是否可用,读写权限,脏….
1ef6d065ab4c851654903930af5fadc2.png
页表每个进程都需要维护

内存的一个地址里面是一个字节(Byte)的数据
32位操作系统物理地址有2^32个,因而只能使用4GB的内存。
任何一个32位的内存可操作的逻辑地址是2^32个即4GB。
上条势必会造成多个程序使用的总内存和大于物理内存,此时会借助磁盘,将不着急用的内存先放进磁盘,页表中显示的是磁盘。

内存映射的过程。

32位系统,256MB内存,页大小为4KB(有四千条地址)
32位程序
4KB = 2^12 bit

也就是说,1个页中提供12位偏移
逻辑地址 32bit = 20bit页号(32-12)bit + 12bit偏移
物理地址 28bit = 16(28-16)bit,即16bit帧号 + 12bit偏移

分页过程中,需要两次读内存时间上有待优化,页表占用空间较大空间上也有待优化(先读内存中的页表,再去拿到对应的地址)

分页中的时间与空间优化。
TLB快标,将最长访问的8-128个页表项存到访问速度更快的硬件中,一般是在MMU中(集成在CPU中)

内存管理-分段 segment 段号+页号
段仅仅保留了逻辑上的意义。
进程间通信-共享内存方式

Cpu的cache如何起作用:

CPU接收到指令后,它会最先向CPU中的一级缓存(L1 Cache)去寻找相关的数据,然一级缓存是与CPU同频运行的,但是由于容量较小,所以不可能每次都命中。这时CPU会继续向下一级的二级缓存(L2 Cache)寻找,同样的道理,当所需要的数据在二级缓存中也没有的话,会继续转向L3 Cache、内存(主存)和硬盘.

984a1ab88c7ba5734a4106cb080a49d6.png

Using Git

Intro

The git directory acts as a database for all the changes tracked in Git and the working tree acts as a sandbox where we can edit the current version of the files

Staging Area(index)

A  file maintained by Git that contains all of the information about what files and changes are going to go into your next commit

Any Git project will consist of 3 sections: Git directory, working tree, Staging area

After modifying a file, we need to stage those changes and then commit them afterwards

chmod +x all_check.py //makes the scripts excutable

A commit message is required, or the commit will be aborted

which command would we use to view pending changes?
git status 

to generate a patch to fix the current bug
diff fix_permission.py fix_permissions_modified.py > fix_permission.patch

apply the patch to the file:
patch fix_names.conf < fix_names.patch 

the wdiff commandhighlights the words that changed in a file instead of working by line

A commit is a collection of edits which has been submitted to the version control system for safe keeping

Within a VCS, project files are organized in centralized locations called repositories where they can be called upon later

Git 常见命令

git add will add a file to the staging area and mark it for tracking

git log will give us information about the author of each commit, its timestamp, and each commit message

git config -l is used to check the current user configuration

git status is used to retrieve information about changes waiting to be committed

user@ubuntu: ~$ git config --global user.email "me@example.com"
user@ubuntu: ~$ git config --global user.name "My name"

Workflow

init git:

user@ubuntu: ~$ mkdir checks
user@ubuntu: ~$ cd checks
user@ubuntu: ~/checks$ git init
Initialized empty Git repository in /home/user/checks/.git/

The area outside the git directory is the working tree. The working tree is the current version of your project.

add git

-m to pass the commit message
user@ubuntu: ~/checks$ git commit -m 'Add periods to the end of sentences.'

anatomy of a  Commit Message

  • short summary
  • detailed explaation
  • more infomation related to the message

git log :
4a214c047c5e1c49c6c1edc7b0703ee8.png
git log -p 

git commit -a 
A shortcut to stage any changes to tracked files and commit them in one step
git commit -a dosen’t work on new files

Can only write short message

user@ubuntu:~/scripts$ git commit -a -m "Call check_reboot from main, exit with 1 on error"

for truely small changes

Git uses the HEAD alias to represent the currently checked-out snapshot of your project.

This lets you know what the contents of your working directory should be.

user@ubuntu:~/scripts$ git add -p

#when using -p flag, git will show us the change being added and ask us if we want to stage it or not

user@ubuntu:~/scripts$ git diff #only unstaged changes by default

user@ubuntu:~/scripts$ git diff -staged #to see the changes that are staged but not committed

we can see the actual stage changes before we call git commit

You can remove files from your repository with the git rm command, which will stop the file from being tracked by git and remove it from the git directory

git checkout
followed by the name of the file you want to revert.

git reset

We’ve added something to the staging area that we didn’t actually want to commit, we can unstage our changes by using git reset.

git add
end up adding any change done in the working tree to the staing area

--amend
git commit --amend
overwirte the previous commit

Avoid amending commits that have already been made public

With git revert, a new commit is created with inverse changes. This cancels previous changes instead of making it as though the original commit never happened.

You can verify the data you get back out is the exact same data you put in

git show

help us easily view the log message and diff output the last commit if we don’t know the commit ID

8d7f473673c37118f4219256950412bc.png

git show hashcommitid
ca21b42d229ac74ac7320a1603bb76d4.png

git revert hashcommitid
user@ubuntu:~/scripts$ git revert 30e70