Merge branch 'develop' of http://git.trustie.net/wrm1995/codepedia2 into develop
This commit is contained in:
commit
c8ef7e15fc
|
@ -15,7 +15,7 @@ from .models import AnnotationComment, QuestionComment, QuestionAnswerComment, A
|
|||
from .models import Vote
|
||||
from users.models import User
|
||||
from .forms import NewArticleForm
|
||||
from projects.models import File
|
||||
from projects.models import File,Method
|
||||
from projects.models import Language, Project, FileSummary
|
||||
from django.template.loader import render_to_string
|
||||
import base64
|
||||
|
@ -328,6 +328,8 @@ class AddAnnotationView(View):
|
|||
annotation.save()
|
||||
# 获取当前文件的注释符号
|
||||
anno_content = get_currentfile_comment_anno(file,content)
|
||||
# 更新FileSummary
|
||||
update_filesummary(file_id,"annotation")
|
||||
# print(anno_content)
|
||||
return HttpResponse('{"status":"success","msg":"注释成功","anno_content":"'+anno_content+'"}', content_type='application/json')
|
||||
except Exception as e:
|
||||
|
@ -335,6 +337,32 @@ class AddAnnotationView(View):
|
|||
else:
|
||||
return HttpResponse('{"status":"fail","msg":"注释失败"}', content_type='application/json')
|
||||
|
||||
def update_filesummary(file_id,type_1):
|
||||
# 不仅要更新自己的FileSummary,而且要更新父目录的FileSummary
|
||||
# 获取当前的FileSummary
|
||||
summarys = []
|
||||
|
||||
project = File.objects.get(id=file_id).project
|
||||
current_summary = FileSummary.objects.get(file_id=file_id,project=project)
|
||||
while current_summary.current_path != "":
|
||||
summarys.append(current_summary)
|
||||
current_summary = FileSummary.objects.get(current_path=current_summary.parent_path,project=project)
|
||||
summarys.append(current_summary)
|
||||
|
||||
for summary in summarys:
|
||||
if type_1=="annotation":
|
||||
summary.anno_num += 1
|
||||
# 如果当前文件没有has_annotation,则将其设置为True
|
||||
file = File.objects.get(id=file_id)
|
||||
if not file.has_annotation:
|
||||
file.has_annotation=True
|
||||
file.save()
|
||||
elif type_1=="issue":
|
||||
summary.isuue_num += 1
|
||||
elif type_1=="question":
|
||||
summary.question_num += 1
|
||||
summary.save()
|
||||
|
||||
def get_currentfile_comment_anno(file,anno_content):
|
||||
if file.name.endswith(".py"):
|
||||
return "# "+anno_content
|
||||
|
@ -433,6 +461,9 @@ class AddQuestionView(View):
|
|||
else:
|
||||
return HttpResponse('{"status":"fail","msg":"参数错误,提问失败"}', content_type='application/json')
|
||||
question.save()
|
||||
# 更新filesummary
|
||||
update_filesummary(file_id,"question")
|
||||
|
||||
return HttpResponse('{"status":"success","msg":"提问成功"}', content_type='application/json')
|
||||
else:
|
||||
return HttpResponse('{"status":"fail","msg":"提问失败"}', content_type='application/json')
|
||||
|
@ -953,43 +984,8 @@ def get_project_info(project_id):
|
|||
question_sum = len(Question.objects.filter(project_id=project_id))
|
||||
issue_question_sum = issue_sum + question_sum
|
||||
|
||||
|
||||
# 参与用户数
|
||||
usersum = len(annos.values('user_id').annotate(user_num=Count('user_id')))
|
||||
annoted_method_num = 0
|
||||
# 获取文件信息和热门问题
|
||||
anno_filenum = len(annos.values(
|
||||
'file_id').annotate(file_num=Count('file_id')))
|
||||
anno_issue_summarys = FileSummary.objects.filter(project_id=project_id, parent_path="")
|
||||
|
||||
#当前文件夹下所有的file_ids以及fileid与filename的映射
|
||||
file_ids = []
|
||||
fileid_name_anno_issue = {}
|
||||
for summary in anno_issue_summarys:
|
||||
file_ids.append(summary.file_id)
|
||||
fileid_name_anno_issue[summary.file_id] = [summary.file.name, 0, 0]
|
||||
|
||||
annos = Annotation.objects.filter(file_id__in=file_ids)
|
||||
fileid_annonum = annos.values(
|
||||
'file_id').annotate(anno_num=Count('file_id'))
|
||||
fileid_issuenum = Issue.objects.filter(file_id__in=file_ids).values(
|
||||
'file_id').annotate(issue_num=Count('file_id'))
|
||||
fileid_questionnum = Question.objects.filter(file_id__in=file_ids).values(
|
||||
'file_id').annotate(question_num=Count('file_id'))
|
||||
|
||||
for i in range(len(fileid_annonum)):
|
||||
file_id = fileid_annonum[i]['file_id']
|
||||
anno_num = fileid_annonum[i]['anno_num']
|
||||
fileid_name_anno_issue[file_id][1] = anno_num
|
||||
|
||||
for i in range(len(fileid_issuenum)):
|
||||
file_id = fileid_issuenum[i]['file_id']
|
||||
issue_num = fileid_issuenum[i]['issue_num']
|
||||
fileid_name_anno_issue[file_id][2] = issue_num
|
||||
|
||||
# 获取本文件夹的注释和问题数目
|
||||
anno_num = len(Annotation.objects.filter(file_id=file_id))
|
||||
question_num = len(Question.objects.filter(file_id=file_id))
|
||||
|
||||
# 获取方法数目,行数,以及文件数
|
||||
summary = FileSummary.objects.get(project_id=project_id, parent_path="self")
|
||||
|
@ -997,24 +993,51 @@ def get_project_info(project_id):
|
|||
line_sum = summary.line_num
|
||||
file_sum = summary.file_num
|
||||
|
||||
files = File.objects.filter(project_id=project_id,has_annotation=True)
|
||||
anno_filenum = len(files)
|
||||
print(files)
|
||||
# import time
|
||||
# current_time = time.time()
|
||||
fileid_name_anno_issue = get_fileid_name_anno_issue(files)
|
||||
|
||||
# before_time = current_time
|
||||
# current_time = time.time()
|
||||
# print("fileid_name_anno_issue cost time:"+str(current_time-before_time))
|
||||
file_ids = []
|
||||
for file in files:
|
||||
file_ids.append(file.id)
|
||||
annoted_method_num= get_annoted_method_num(file_ids)
|
||||
|
||||
# before_time = current_time
|
||||
# current_time = time.time()
|
||||
# print("fileid_name_anno_issue cost time:"+str(current_time-before_time))
|
||||
# print(annoted_method_num)
|
||||
|
||||
html_str = render_to_string('projects/filesub/dir_info.html', locals())
|
||||
return html_str
|
||||
|
||||
# def get_files_method_lines(file_id):
|
||||
# file = File.objects.get(id=file_id)
|
||||
# file_path = file.path
|
||||
# project_path = file.project.name
|
||||
# lines=[]
|
||||
# try:
|
||||
# all_symbols,_ =get_navigation_content(project_path,file_path)
|
||||
# for i in range(len(all_symbols)):
|
||||
# symbol = all_symbols[i]
|
||||
# if symbol[0]=='Method' or symbol[0]=='Function':
|
||||
# for j in range(len(symbol[1])):
|
||||
# lines.append(symbol[1][j][1])
|
||||
# return lines
|
||||
# except:
|
||||
# return lines
|
||||
|
||||
def get_files_method_lines(file_id):
|
||||
file = File.objects.get(id=file_id)
|
||||
file_path = file.path
|
||||
project_path = file.project.name
|
||||
lines=[]
|
||||
try:
|
||||
all_symbols,_ =get_navigation_content(project_path,file_path)
|
||||
for i in range(len(all_symbols)):
|
||||
symbol = all_symbols[i]
|
||||
if symbol[0]=='Method' or symbol[0]=='Function':
|
||||
for j in range(len(symbol[1])):
|
||||
lines.append(symbol[1][j][1])
|
||||
return lines
|
||||
except:
|
||||
return lines
|
||||
lines = []
|
||||
methods = Method.objects.filter(file_id=file_id).values('line_num')
|
||||
for method in methods:
|
||||
lines.append(method['line_num'])
|
||||
return lines
|
||||
|
||||
def get_annoted_method_num(file_ids):
|
||||
# 获取annoted_method
|
||||
|
@ -1026,64 +1049,65 @@ def get_annoted_method_num(file_ids):
|
|||
file_id = file_ids[i]
|
||||
method_lines = get_files_method_lines(file_id)
|
||||
if method_lines is None:
|
||||
return 0
|
||||
for j in range(len(method_lines)):
|
||||
current_line = method_lines[j]
|
||||
if len(Annotation.objects.filter(file_id__in=file_ids,linenum=current_line))>0:
|
||||
annoted_method_num = annoted_method_num + 1
|
||||
return annoted_method_num
|
||||
continue
|
||||
for i in range(len(method_lines)):
|
||||
method_line = method_lines[i]
|
||||
if len(Annotation.objects.filter(file_id=file_id,linenum=method_line))>0:
|
||||
annoted_method_num +=1
|
||||
return annoted_method_num
|
||||
|
||||
# def get_annoted_method_num(file_ids):
|
||||
# # 获取annoted_method
|
||||
# # 以file为基本单位
|
||||
# # 1.获取method对应的行
|
||||
# # 2.获取该行是否有注释
|
||||
# annoted_method_num=0
|
||||
# for i in range(len(file_ids)):
|
||||
# file_id = file_ids[i]
|
||||
# method_lines = get_files_method_lines(file_id)
|
||||
# if method_lines is None:
|
||||
# continue
|
||||
# for j in range(len(method_lines)):
|
||||
# current_line = method_lines[j]
|
||||
# if len(Annotation.objects.filter(file_id=file_id,linenum=current_line))>0:
|
||||
# annoted_method_num = annoted_method_num + 1
|
||||
# return annoted_method_num
|
||||
# 调用api接口
|
||||
|
||||
def get_currentpath_all_annoted_sub_files(project_id,current_path):
|
||||
files = File.objects.filter(type=0,path__startswith=current_path+"/",has_annotation=True)
|
||||
return files
|
||||
|
||||
def get_dir_info(project_id,path):
|
||||
# 获取当前文件的注释总数以及问题总数
|
||||
# 不需要累计的,只需要当前的即可了
|
||||
file_id = File.objects.get(project_id=project_id,path=path).pk
|
||||
anno_issue_summarys = FileSummary.objects.filter(project_id=project_id,parent_path=path)
|
||||
anno_issue_summary = FileSummary.objects.filter(project_id=project_id,current_path=path)
|
||||
|
||||
#当前文件夹下所有的file_ids以及fileid与filename的映射
|
||||
files = get_currentpath_all_annoted_sub_files(project_id,path)
|
||||
anno_filenum = len(files)
|
||||
# [name,anno,issue]
|
||||
fileid_name_anno_issue = get_fileid_name_anno_issue(files)
|
||||
|
||||
file_ids = []
|
||||
fileid_name_anno_issue = {}
|
||||
for summary in anno_issue_summarys:
|
||||
file_ids.append(summary.file_id)
|
||||
fileid_name_anno_issue[summary.file_id] = [summary.file.name,0,0]
|
||||
|
||||
annos = Annotation.objects.filter(file_id__in=file_ids)
|
||||
fileid_annonum = annos.values('file_id').annotate(anno_num=Count('file_id'))
|
||||
fileid_issuenum = Issue.objects.filter(file_id__in=file_ids).values('file_id').annotate(issue_num=Count('file_id'))
|
||||
fileid_questionnum = Question.objects.filter(file_id__in=file_ids).values('file_id').annotate(question_num=Count('file_id'))
|
||||
usersum = len(annos.values('user_id').annotate(user_num=Count('user_id')))
|
||||
|
||||
for file in files:
|
||||
file_ids.append(file.id)
|
||||
annoted_method_num= get_annoted_method_num(file_ids)
|
||||
|
||||
anno_sum,issue_sum,question_sum=0,0,0
|
||||
anno_filenum=0
|
||||
for i in range(len(fileid_annonum)):
|
||||
anno_filenum +=1
|
||||
current_file_id = fileid_annonum[i]['file_id']
|
||||
anno_num = fileid_annonum[i]['anno_num']
|
||||
anno_sum+= anno_num
|
||||
fileid_name_anno_issue[current_file_id][1] = anno_num
|
||||
|
||||
for i in range(len(fileid_issuenum)):
|
||||
current_file_id = fileid_issuenum[i]['file_id']
|
||||
issue_num = fileid_issuenum[i]['issue_num']
|
||||
issue_sum += issue_num
|
||||
fileid_name_anno_issue[current_file_id][2] = issue_num
|
||||
|
||||
for i in range(len(fileid_questionnum)):
|
||||
question_sum += fileid_questionnum[i]['question_num']
|
||||
|
||||
issue_question_sum = issue_sum + question_sum
|
||||
print(issue_question_sum)
|
||||
|
||||
anno_num = len(Annotation.objects.filter(file_id=file_id))
|
||||
question_num = len(Question.objects.filter(file_id=file_id))
|
||||
|
||||
involved_userset =set()
|
||||
for file in files:
|
||||
users = Annotation.objects.filter(file=file).values('user_id').distinct()
|
||||
for user in users:
|
||||
involved_userset.add(user['user_id'])
|
||||
usersum=len(involved_userset)
|
||||
|
||||
current_file_summary = FileSummary.objects.get(project_id=project_id,current_path=path)
|
||||
line_sum = current_file_summary.line_num
|
||||
method_sum = current_file_summary.method_num
|
||||
file_sum = current_file_summary.file_num
|
||||
anno_sum = current_file_summary.anno_num
|
||||
issue_question_sum = current_file_summary.isuue_num + current_file_summary.question_num
|
||||
|
||||
html_str = render_to_string('projects/filesub/dir_info.html', locals())
|
||||
return html_str
|
||||
|
@ -1091,6 +1115,28 @@ def get_dir_info(project_id,path):
|
|||
# 获取当前文件夹各文件的注释数目以及问题数目
|
||||
# 获取当前文件夹的各文件
|
||||
|
||||
def get_fileid_name_anno_issue(files):
|
||||
annoted_file_annonum_map = {}
|
||||
for file in files:
|
||||
anno_length = len(Annotation.objects.filter(file=file))
|
||||
annoted_file_annonum_map[file]=anno_length
|
||||
print(anno_length)
|
||||
|
||||
annoted_file_annonum_list = sorted(annoted_file_annonum_map.items(), key=lambda annoted_file_annonum_map:annoted_file_annonum_map[1],reverse=True)
|
||||
# 返回前5个
|
||||
fileid_name_anno_issue={}
|
||||
range_length = len(annoted_file_annonum_list)
|
||||
if len(annoted_file_annonum_list)>=5:
|
||||
range_length = 5
|
||||
for i in range(range_length):
|
||||
file=annoted_file_annonum_list[i][0]
|
||||
annonum = annoted_file_annonum_list[i][1]
|
||||
fileid_name_anno_issue[file.id]=[]
|
||||
fileid_name_anno_issue[file.id].append(file.name)
|
||||
fileid_name_anno_issue[file.id].append(annonum)
|
||||
current_file_summary = FileSummary.objects.get(file=file)
|
||||
fileid_name_anno_issue[file.id].append(current_file_summary.question_num)
|
||||
return fileid_name_anno_issue
|
||||
|
||||
def getAnnotationByFileId():
|
||||
pass
|
||||
|
@ -1159,35 +1205,16 @@ class RightView(View):
|
|||
file = File.objects.get(id=file_id)
|
||||
project_id = file.project.id
|
||||
path = file.path
|
||||
anno_issue_summarys = FileSummary.objects.filter(project_id=project_id,parent_path=path)
|
||||
|
||||
#当前文件夹下所有的file_ids以及fileid与filename的映射
|
||||
file_ids = []
|
||||
for summary in anno_issue_summarys:
|
||||
file_ids.append(summary.file_id)
|
||||
|
||||
anno_num,issue_num,question_num=0,0,0
|
||||
|
||||
annos = Annotation.objects.filter(file_id__in=file_ids)
|
||||
fileid_annonum = annos.values('file_id').annotate(anno_num=Count('file_id'))
|
||||
for i in range(len(fileid_annonum)):
|
||||
anno_num += fileid_annonum[i]['anno_num']
|
||||
|
||||
fileid_issuenum = Issue.objects.filter(file_id__in=file_ids).values('file_id').annotate(issue_num=Count('file_id'))
|
||||
for i in range(len(fileid_issuenum)):
|
||||
issue_num += fileid_issuenum[i]['issue_num']
|
||||
|
||||
fileid_questionnum = Question.objects.filter(file_id__in=file_ids).values('file_id').annotate(question_num=Count('file_id'))
|
||||
for i in range(len(fileid_questionnum)):
|
||||
question_num += fileid_questionnum[i]['question_num']
|
||||
|
||||
files = get_currentpath_all_annoted_sub_files(project_id,file.path)
|
||||
view_num = 0
|
||||
for i in range(len(file_ids)):
|
||||
view_num += File.objects.get(id=file_ids[i]).views
|
||||
|
||||
issue_question_num = issue_num + question_num
|
||||
for file in files:
|
||||
view_num += file.views
|
||||
|
||||
current_file_summary = FileSummary.objects.get(project_id=project_id,current_path=path)
|
||||
|
||||
issue_question_num = current_file_summary.isuue_num + current_file_summary.question_num
|
||||
anno_num = current_file_summary.anno_num
|
||||
filelinenum = current_file_summary.line_num
|
||||
create_time = file.create_time
|
||||
file_num = current_file_summary.file_num
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 2.0.6 on 2018-08-24 00:18
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('projects', '0011_filesummary_current_path'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='filesummary',
|
||||
name='question_num',
|
||||
field=models.IntegerField(default=0, verbose_name='用户提问总数'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='filesummary',
|
||||
name='isuue_num',
|
||||
field=models.IntegerField(default=0, verbose_name='系统问题总数'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,29 @@
|
|||
# Generated by Django 2.0.6 on 2018-08-24 10:55
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('projects', '0012_auto_20180824_0018'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Method',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('line_num', models.IntegerField(default=0, verbose_name='代码总数')),
|
||||
('name', models.CharField(default='', max_length=255, verbose_name='函数名')),
|
||||
('file', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.File', verbose_name='文件')),
|
||||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.Project', verbose_name='项目')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '函数',
|
||||
'verbose_name_plural': '函数',
|
||||
'db_table': 'Method',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,26 @@
|
|||
# Generated by Django 2.0.6 on 2018-08-24 14:15
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('projects', '0013_method'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='file',
|
||||
name='anno_num',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='file',
|
||||
name='issue_num',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='file',
|
||||
name='has_annotation',
|
||||
field=models.BooleanField(default=False, verbose_name='是否有标注'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 2.0.6 on 2018-08-24 16:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('projects', '0014_auto_20180824_1415'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='file',
|
||||
name='anno_num',
|
||||
field=models.IntegerField(default=0, verbose_name='注释数量'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='file',
|
||||
name='issue_num',
|
||||
field=models.IntegerField(default=0, verbose_name='注释数量'),
|
||||
),
|
||||
]
|
|
@ -79,6 +79,8 @@ class File(models.Model):
|
|||
update_time = models.DateTimeField(auto_now=True)
|
||||
anno_num = models.IntegerField(default=0, verbose_name='注释数量')
|
||||
issue_num = models.IntegerField(default=0, verbose_name='注释数量')
|
||||
has_annotation = models.BooleanField(default=False, verbose_name='是否有标注')
|
||||
|
||||
|
||||
class Meta:
|
||||
db_table = 'Source_File'
|
||||
|
@ -132,12 +134,24 @@ class FileAnnoIssueSummary(models.Model):
|
|||
verbose_name = "文件注释问题总数"
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
class Method(models.Model):
|
||||
project = models.ForeignKey(Project, verbose_name='项目', on_delete=models.CASCADE)
|
||||
file = models.ForeignKey(File, verbose_name='文件', on_delete=models.CASCADE)
|
||||
line_num = models.IntegerField(default=0, verbose_name='代码总数')
|
||||
name = models.CharField(default="",max_length=255, verbose_name='函数名')
|
||||
|
||||
class Meta:
|
||||
db_table = 'Method'
|
||||
verbose_name = "函数"
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
class FileSummary(models.Model):
|
||||
project = models.ForeignKey(
|
||||
Project, verbose_name='文件', on_delete=models.CASCADE)
|
||||
file = models.ForeignKey(File, verbose_name='文件', on_delete=models.CASCADE)
|
||||
anno_num = models.IntegerField(default=0, verbose_name='注释总数')
|
||||
isuue_num = models.IntegerField(default=0, verbose_name='问题总数')
|
||||
isuue_num = models.IntegerField(default=0, verbose_name='系统问题总数')
|
||||
question_num = models.IntegerField(default=0, verbose_name='用户提问总数')
|
||||
parent_path = models.CharField(default="",max_length=255, verbose_name='父文件夹路径')
|
||||
line_num = models.IntegerField(default=0, verbose_name='代码总数')
|
||||
method_num = models.IntegerField(default=0, verbose_name='方法总数')
|
||||
|
|
|
@ -41,7 +41,8 @@ class NewProjectView(View):
|
|||
# logging.info(str(datetime.now()) + '准备导入工程')
|
||||
import_project(project_id, root_path)
|
||||
# scanner_project
|
||||
scanner_project.get_anno_issue_summary("/opt/opengrok/source/"+project.name, project.id)
|
||||
scanner_project_obj = scanner_project.Scanner_Project_Object()
|
||||
scanner_project_obj.get_anno_issue_summary("/opt/opengrok/source/"+project.name, project.id)
|
||||
# 设置默认的权限,默认为所有人都可以看见
|
||||
stragegy = AnnotationStrategy()
|
||||
stragegy.project = project
|
||||
|
@ -205,8 +206,8 @@ class ScannerProjectView(View):
|
|||
project_name = request.GET.get('project_name','')
|
||||
try:
|
||||
project = Project.objects.get(name=project_name)
|
||||
print(1111)
|
||||
scanner_project.get_anno_issue_summary("/opt/opengrok/source/"+project_name, project.pk)
|
||||
scanner_project_obj = scanner_project.Scanner_Project_Object()
|
||||
scanner_project_obj.get_anno_issue_summary("/opt/opengrok/source/"+project_name, project.pk)
|
||||
return HttpResponse("Scanner Done!!")
|
||||
except:
|
||||
return HttpResponse("Scanner Fail!!")
|
||||
|
|
|
@ -20,6 +20,8 @@ from pure_pagination import Paginator, EmptyPage, PageNotAnInteger
|
|||
from operations.models import Annotation,AnnotationComment
|
||||
import linecache
|
||||
|
||||
import random
|
||||
|
||||
|
||||
# Create your views here.
|
||||
# 搜索自定义django auther
|
||||
|
@ -238,6 +240,11 @@ class LoginView(View):
|
|||
|
||||
user = User()
|
||||
user.username = response['username']
|
||||
|
||||
|
||||
while User.objects.filter(username=user.username).first():
|
||||
user.username += str(random.randint(0,10))
|
||||
|
||||
user.password = make_password(pass_word)
|
||||
user.password_codepedia = user.password
|
||||
user.educoder_userid = int(educoder_userid)
|
||||
|
|
|
@ -1,198 +1,234 @@
|
|||
from operations.models import Annotation,Issue
|
||||
from projects.models import File,Project
|
||||
from operations.models import Annotation,Issue,Question
|
||||
from projects.models import File,Project,Method
|
||||
from django.db.models import Count
|
||||
from projects.models import FileSummary
|
||||
import os
|
||||
|
||||
class Scanner_Project_Object:
|
||||
|
||||
project_name=""
|
||||
fileid_anno_sum = {}
|
||||
fileid_issue_sum = {}
|
||||
fileid_parentpath = {}
|
||||
filepath_id, fileid_annonum,fileid_issuenum=None,None,None
|
||||
def __init__(self):
|
||||
self.project_name=""
|
||||
|
||||
fileid_method_sum = {}
|
||||
fileid_file_sum = {}
|
||||
fileid_line_sum = {}
|
||||
self.filepath_id_map = None
|
||||
|
||||
self.fileid_annonum_map = None
|
||||
self.fileid_issuenum_map= None
|
||||
self.fileid_questionnum_map= None
|
||||
|
||||
self.fileid_parentpath = {}
|
||||
self.fileid_anno_sum = {}
|
||||
self.fileid_issue_sum = {}
|
||||
self.fileid_question_sum = {}
|
||||
|
||||
self.fileid_method_sum = {}
|
||||
self.fileid_file_sum = {}
|
||||
self.fileid_line_sum = {}
|
||||
self.fileid_annoted_method_sum = {}
|
||||
|
||||
|
||||
def get_anno_issue_summary(project_path,project_id):
|
||||
global project_name, filepath_id, fileid_annonum, fileid_issuenum,fileid_parentpath,fileid_method_sum,fileid_file_sum,fileid_line_sum,fileid_anno_sum,fileid_issue_sum
|
||||
|
||||
project_name = project_path[project_path.rfind('/')+1:]
|
||||
print(project_name)
|
||||
def get_anno_issue_summary(self,project_path,project_id):
|
||||
|
||||
self.project_name = project_path[project_path.rfind('/')+1:]
|
||||
print(self.project_name)
|
||||
|
||||
filepath_id = getPathFileIdInfo(project_id)
|
||||
fileid_annonum = getFileAnnoInfo(project_id)
|
||||
fileid_issuenum = getFileIssueInfo(project_id)
|
||||
self.filepath_id_map = self.getPathFileIdInfo(project_id)
|
||||
self.fileid_annonum_map = self.getFileAnnoInfo(project_id)
|
||||
self.fileid_issuenum_map = self.getFileIssueInfo(project_id)
|
||||
self.fileid_questionnum_map = self.getFileQuestionInfo(project_id)
|
||||
|
||||
# print(filepath_id)
|
||||
projectAnnoNum,projectIssueNum=deepSearch(project_path)
|
||||
projectMethods,projectFiles,projectLines = deepSearchForMethod(project_path)
|
||||
# print(self.filepath_id_map)
|
||||
projectAnnoNum,projectIssueNum,projectQuestionNum = self.deepSearch(project_path)
|
||||
projectMethods,projectFiles,projectLines = self.deepSearchForMethod(project_path)
|
||||
|
||||
root_fileid = filepath_id[""]
|
||||
fileid_anno_sum[root_fileid]=projectAnnoNum
|
||||
fileid_issue_sum[root_fileid]=projectIssueNum
|
||||
fileid_parentpath[root_fileid]="self"
|
||||
root_fileid = self.filepath_id_map[""]
|
||||
self.fileid_anno_sum[root_fileid]=projectAnnoNum
|
||||
self.fileid_issue_sum[root_fileid]=projectIssueNum
|
||||
self.fileid_question_sum[root_fileid]=projectQuestionNum
|
||||
self.fileid_parentpath[root_fileid]="self"
|
||||
|
||||
fileid_file_sum[root_fileid]=projectFiles
|
||||
fileid_method_sum[root_fileid]=projectMethods
|
||||
fileid_line_sum[root_fileid]=projectLines
|
||||
self.fileid_file_sum[root_fileid]=projectFiles
|
||||
self.fileid_method_sum[root_fileid]=projectMethods
|
||||
self.fileid_line_sum[root_fileid]=projectLines
|
||||
|
||||
save(project_id)
|
||||
self.save(project_id)
|
||||
|
||||
|
||||
def save(project_id):
|
||||
for file_id in filepath_id.values():
|
||||
print(file_id)
|
||||
try:
|
||||
obj = FileSummary.objects.get(file_id=file_id)
|
||||
except:
|
||||
print(111)
|
||||
obj = FileSummary()
|
||||
obj.file = File.objects.get(pk=file_id)
|
||||
obj.project = Project.objects.get(pk=project_id)
|
||||
def save(self,project_id):
|
||||
for file_id in self.filepath_id_map.values():
|
||||
# print(file_id)
|
||||
try:
|
||||
obj = FileSummary.objects.get(file_id=file_id)
|
||||
except:
|
||||
obj = FileSummary()
|
||||
obj.file = File.objects.get(pk=file_id)
|
||||
obj.project = Project.objects.get(pk=project_id)
|
||||
|
||||
if file_id not in fileid_anno_sum:
|
||||
continue
|
||||
obj.anno_num = fileid_anno_sum[file_id]
|
||||
obj.isuue_num = fileid_issue_sum[file_id]
|
||||
obj.parent_path = fileid_parentpath[file_id]
|
||||
obj.file_num = fileid_file_sum[file_id]
|
||||
obj.line_num = fileid_line_sum[file_id]
|
||||
obj.method_num = fileid_method_sum[file_id]
|
||||
obj.current_path = obj.file.path
|
||||
obj.save()
|
||||
if file_id not in self.fileid_anno_sum:
|
||||
continue
|
||||
obj.anno_num = self.fileid_anno_sum[file_id]
|
||||
obj.isuue_num = self.fileid_issue_sum[file_id]
|
||||
obj.question_num = self.fileid_question_sum[file_id]
|
||||
|
||||
obj.parent_path = self.fileid_parentpath[file_id]
|
||||
obj.file_num = self.fileid_file_sum[file_id]
|
||||
obj.line_num = self.fileid_line_sum[file_id]
|
||||
obj.method_num = self.fileid_method_sum[file_id]
|
||||
obj.current_path = obj.file.path
|
||||
obj.save()
|
||||
|
||||
|
||||
def deepSearch(current_path):
|
||||
global fileid_anno_sum,fileid_issue_sum,fileid_parentpath
|
||||
def deepSearch(self,current_path):
|
||||
|
||||
index=current_path.find(project_name)
|
||||
files = os.listdir(current_path)
|
||||
currentAnnoNum = 0
|
||||
currentIssueNum = 0
|
||||
index=current_path.find(self.project_name)
|
||||
files = os.listdir(current_path)
|
||||
currentAnnoNum = 0
|
||||
currentIssueNum = 0
|
||||
currentQuestionNum = 0
|
||||
|
||||
for i in range(len(files)):
|
||||
filePath = current_path + os.path.sep + files[i]
|
||||
# print(filePath)
|
||||
relative_path = filePath[index+len(project_name):]
|
||||
# 相对路径是否在filepath_id中,可能会有这样的情况,
|
||||
# 路径没有对应的file_id,也就是当前路劲没有收录
|
||||
if relative_path not in filepath_id:
|
||||
continue
|
||||
file_id = filepath_id[relative_path]
|
||||
for i in range(len(files)):
|
||||
filePath = current_path + os.path.sep + files[i]
|
||||
# print(filePath)
|
||||
relative_path = filePath[index+len(self.project_name):]
|
||||
# 相对路径是否在filepath_id中,可能会有这样的情况,
|
||||
# 路径没有对应的file_id,也就是当前路劲没有收录
|
||||
if relative_path not in self.filepath_id_map:
|
||||
continue
|
||||
file_id = self.filepath_id_map[relative_path]
|
||||
|
||||
#获取当前文件/文件夹的父路径
|
||||
if index+len(project_name)>=len(current_path):
|
||||
fileid_parentpath[file_id]=""
|
||||
else:
|
||||
fileid_parentpath[file_id]=current_path[index+len(project_name):]
|
||||
|
||||
#获取当前文件/文件夹下的问题和注释总数
|
||||
if os.path.isdir(filePath):
|
||||
|
||||
annoNum,issueNum= deepSearch(filePath)
|
||||
#还要加上自己本身的问题和注释总数:
|
||||
if file_id in fileid_annonum:
|
||||
fileid_anno_sum[file_id] = annoNum + fileid_annonum[file_id]
|
||||
#获取当前文件/文件夹的父路径
|
||||
if index+len(self.project_name)>=len(current_path):
|
||||
self.fileid_parentpath[file_id]=""
|
||||
else:
|
||||
fileid_anno_sum[file_id] = annoNum
|
||||
|
||||
if file_id in fileid_issuenum:
|
||||
fileid_issue_sum[file_id] = issueNum + fileid_issuenum[file_id]
|
||||
self.fileid_parentpath[file_id]=current_path[index+len(self.project_name):]
|
||||
|
||||
#获取当前文件/文件夹下的问题和注释总数
|
||||
if os.path.isdir(filePath):
|
||||
|
||||
annoNum,issueNum,questionNum= self.deepSearch(filePath)
|
||||
#还要加上自己本身的问题和注释总数:
|
||||
if file_id in self.fileid_annonum_map:
|
||||
self.fileid_anno_sum[file_id] = annoNum + self.fileid_annonum_map[file_id]
|
||||
else:
|
||||
self.fileid_anno_sum[file_id] = annoNum
|
||||
|
||||
if file_id in self.fileid_issuenum_map:
|
||||
self.fileid_issue_sum[file_id] = issueNum + self.fileid_issuenum_map[file_id]
|
||||
else:
|
||||
self.fileid_issue_sum[file_id] = issueNum
|
||||
|
||||
if file_id in self.fileid_questionnum_map:
|
||||
self.fileid_question_sum[file_id] = questionNum + self.fileid_questionnum_map[file_id]
|
||||
else:
|
||||
self.fileid_question_sum[file_id] = questionNum
|
||||
|
||||
currentAnnoNum += self.fileid_anno_sum[file_id]
|
||||
currentIssueNum += self.fileid_issue_sum[file_id]
|
||||
currentQuestionNum += self.fileid_question_sum[file_id]
|
||||
|
||||
else:
|
||||
fileid_issue_sum[file_id] = issueNum
|
||||
|
||||
currentAnnoNum += fileid_anno_sum[file_id]
|
||||
currentIssueNum += fileid_issue_sum[file_id]
|
||||
|
||||
else:
|
||||
if file_id in fileid_annonum:
|
||||
fileid_anno_sum[file_id] = fileid_annonum[file_id]
|
||||
if file_id in self.fileid_annonum_map:
|
||||
self.fileid_anno_sum[file_id] = self.fileid_annonum_map[file_id]
|
||||
file = File.objects.get(id=file_id)
|
||||
file.has_annotation = True
|
||||
file.save()
|
||||
else:
|
||||
self.fileid_anno_sum[file_id] = 0
|
||||
currentAnnoNum += self.fileid_anno_sum[file_id]
|
||||
|
||||
if file_id in self.fileid_issuenum_map:
|
||||
self.fileid_issue_sum[file_id] = self.fileid_issuenum_map[file_id]
|
||||
else:
|
||||
self.fileid_issue_sum[file_id] = 0
|
||||
currentIssueNum += self.fileid_issue_sum[file_id]
|
||||
|
||||
if file_id in self.fileid_questionnum_map:
|
||||
self.fileid_question_sum[file_id] = self.fileid_questionnum_map[file_id]
|
||||
else:
|
||||
self.fileid_question_sum[file_id] = 0
|
||||
currentQuestionNum += self.fileid_question_sum[file_id]
|
||||
|
||||
return currentAnnoNum,currentIssueNum,currentQuestionNum
|
||||
|
||||
|
||||
def getPathFileIdInfo(self,project_id):
|
||||
files = File.objects.filter(project_id=project_id)
|
||||
filepath_id_map = {}
|
||||
for file in files:
|
||||
filepath_id_map[file.path]=file.pk
|
||||
return filepath_id_map
|
||||
|
||||
def getFileAnnoInfo(self,project_id):
|
||||
annos = Annotation.objects.filter(project_id=project_id)
|
||||
fileid_annonum_map={}
|
||||
for anno in annos:
|
||||
if anno.file_id in fileid_annonum_map:
|
||||
fileid_annonum_map[anno.file_id]+=1
|
||||
else:
|
||||
fileid_anno_sum[file_id] = 0
|
||||
currentAnnoNum += fileid_anno_sum[file_id]
|
||||
fileid_annonum_map[anno.file_id]=1
|
||||
return fileid_annonum_map
|
||||
|
||||
if file_id in fileid_issuenum:
|
||||
fileid_issue_sum[file_id] = fileid_issuenum[file_id]
|
||||
def getFileIssueInfo(self,project_id):
|
||||
issues = Issue.objects.filter(project_id=project_id)
|
||||
fileid_issuenum_map = {}
|
||||
for issue in issues:
|
||||
if issue.file_id in fileid_issuenum_map:
|
||||
fileid_issuenum_map[issue.file_id] += 1
|
||||
else:
|
||||
fileid_issue_sum[file_id] = 0
|
||||
currentIssueNum += fileid_issue_sum[file_id]
|
||||
|
||||
return currentAnnoNum,currentIssueNum
|
||||
fileid_issuenum_map[issue.file_id] = 1
|
||||
return fileid_issuenum_map
|
||||
|
||||
def getFileQuestionInfo(self,project_id):
|
||||
question = Question.objects.filter(project_id=project_id)
|
||||
fileid_questionnum_map = {}
|
||||
for question in question:
|
||||
if question.file_id in fileid_questionnum_map:
|
||||
fileid_questionnum_map[question.file_id] += 1
|
||||
else:
|
||||
fileid_questionnum_map[question.file_id] = 1
|
||||
return fileid_questionnum_map
|
||||
|
||||
|
||||
def getPathFileIdInfo(project_id):
|
||||
files = File.objects.filter(project_id=project_id)
|
||||
filepath_id = {}
|
||||
for file in files:
|
||||
filepath_id[file.path]=file.pk
|
||||
return filepath_id
|
||||
def deepSearchForMethod(self,current_path):
|
||||
|
||||
def getFileAnnoInfo(project_id):
|
||||
annos = Annotation.objects.filter(project_id=project_id)
|
||||
fileid_annonum={}
|
||||
for anno in annos:
|
||||
if anno.file_id in fileid_annonum:
|
||||
fileid_annonum[anno.file_id]+=1
|
||||
else:
|
||||
fileid_annonum[anno.file_id]=1
|
||||
return fileid_annonum
|
||||
index=current_path.find(self.project_name)
|
||||
files = os.listdir(current_path)
|
||||
|
||||
def getFileIssueInfo(project_id):
|
||||
issues = Issue.objects.filter(project_id=project_id)
|
||||
fileid_issuenum = {}
|
||||
for issue in issues:
|
||||
if issue.file_id in fileid_issuenum:
|
||||
fileid_issuenum[issue.file_id] += 1
|
||||
else:
|
||||
fileid_issuenum[issue.file_id] = 1
|
||||
return fileid_issuenum
|
||||
currentFiles = 0
|
||||
currentLines = 0
|
||||
currentMethods = 0
|
||||
|
||||
for i in range(len(files)):
|
||||
filePath = current_path + os.path.sep + files[i]
|
||||
# print(filePath)
|
||||
relative_path = filePath[index+len(self.project_name):]
|
||||
# 相对路径是否在filepath_id中,可能会有这样的情况,
|
||||
# 路径没有对应的file_id,也就是当前路劲没有收录
|
||||
if relative_path not in self.filepath_id_map:
|
||||
continue
|
||||
file_id = self.filepath_id_map[relative_path]
|
||||
|
||||
def deepSearchForMethod(current_path):
|
||||
global fileid_method_sum,fileid_line_sum,fileid_file_sum
|
||||
# 获取当前文件/文件夹下的问题和注释总数
|
||||
if os.path.isdir(filePath):
|
||||
methods,filenum,lines= self.deepSearchForMethod(filePath)
|
||||
|
||||
self.fileid_method_sum[file_id] = methods
|
||||
currentMethods += self.fileid_method_sum[file_id]
|
||||
self.fileid_file_sum[file_id] = filenum
|
||||
currentFiles += self.fileid_file_sum[file_id]
|
||||
self.fileid_line_sum[file_id] = lines
|
||||
currentLines += self.fileid_line_sum[file_id]
|
||||
|
||||
else:
|
||||
self.fileid_method_sum[file_id] = getFileMethodCount(self.project_name,relative_path)
|
||||
currentMethods += self.fileid_method_sum[file_id]
|
||||
|
||||
index=current_path.find(project_name)
|
||||
files = os.listdir(current_path)
|
||||
self.fileid_file_sum[file_id] = 1
|
||||
currentFiles += self.fileid_file_sum[file_id]
|
||||
|
||||
currentFiles = 0
|
||||
currentLines = 0
|
||||
currentMethods = 0
|
||||
|
||||
for i in range(len(files)):
|
||||
filePath = current_path + os.path.sep + files[i]
|
||||
# print(filePath)
|
||||
relative_path = filePath[index+len(project_name):]
|
||||
# 相对路径是否在filepath_id中,可能会有这样的情况,
|
||||
# 路径没有对应的file_id,也就是当前路劲没有收录
|
||||
if relative_path not in filepath_id:
|
||||
continue
|
||||
file_id = filepath_id[relative_path]
|
||||
|
||||
# 获取当前文件/文件夹下的问题和注释总数
|
||||
if os.path.isdir(filePath):
|
||||
methods,filenum,lines= deepSearchForMethod(filePath)
|
||||
|
||||
fileid_method_sum[file_id] = methods
|
||||
currentMethods += fileid_method_sum[file_id]
|
||||
fileid_file_sum[file_id] = filenum
|
||||
currentFiles += fileid_file_sum[file_id]
|
||||
fileid_line_sum[file_id] = lines
|
||||
currentLines += fileid_line_sum[file_id]
|
||||
|
||||
else:
|
||||
fileid_method_sum[file_id] = getFileMethodCount(project_name,relative_path)
|
||||
currentMethods += fileid_method_sum[file_id]
|
||||
|
||||
fileid_file_sum[file_id] = 1
|
||||
currentFiles += fileid_file_sum[file_id]
|
||||
|
||||
fileid_line_sum[file_id] = getFileLineNum(project_name,relative_path)
|
||||
currentLines += fileid_line_sum[file_id]
|
||||
|
||||
return currentMethods,currentFiles,currentLines
|
||||
self.fileid_line_sum[file_id] = getFileLineNum(self.project_name,relative_path)
|
||||
currentLines += self.fileid_line_sum[file_id]
|
||||
|
||||
return currentMethods,currentFiles,currentLines
|
||||
|
||||
import json
|
||||
from django.conf import settings
|
||||
|
@ -205,22 +241,35 @@ def getFileMethodCount(project_path,file_path):
|
|||
navigation_url = settings.OPENGROK_NAVIGATION_URL
|
||||
navigation_url = navigation_url +project_path + file_path
|
||||
response = requests.get(navigation_url).text
|
||||
project_id = Project.objects.get(name=project_path)
|
||||
file_id = File.objects.get(project_id=project_id,path=file_path).pk
|
||||
return analysis_opengrok_naviation_for_method_num(response)
|
||||
except:
|
||||
project = Project.objects.get(name=project_path)
|
||||
file = File.objects.get(project=project,path=file_path)
|
||||
return analysis_opengrok_naviation_for_method_num(response,project,file)
|
||||
except Exception as e:
|
||||
return 0;
|
||||
|
||||
def analysis_opengrok_naviation_for_method_num(response):
|
||||
def analysis_opengrok_naviation_for_method_num(response,project,file):
|
||||
response = response.replace("]],[","]]|[")
|
||||
if response:
|
||||
# 应该查找的是Function或者Method的长度才对
|
||||
all_symbols = response.split("|")
|
||||
if len(all_symbols)>=1:
|
||||
for i in range(len(all_symbols)):
|
||||
symbol = json.loads(all_symbols[i])
|
||||
if symbol[0]=='Method' or symbol[0]=='Function':
|
||||
return len(symbol[2])
|
||||
|
||||
for i in range(len(all_symbols)):
|
||||
symbol = json.loads(all_symbols[i])
|
||||
if symbol[0]=='Method' or symbol[0]=='Function':
|
||||
for j in range(len(symbol[2])):
|
||||
method_name = symbol[2][j][0]
|
||||
method_linenum = symbol[2][j][1]
|
||||
try:
|
||||
method = Method.objects.get(project=project,file=file,line_num=method_linenum)
|
||||
except:
|
||||
method = Method()
|
||||
finally:
|
||||
method.project = project
|
||||
method.file = file
|
||||
method.name = method_name
|
||||
method.line_num = method_linenum
|
||||
method.save()
|
||||
return len(symbol[2])
|
||||
return 0;
|
||||
|
||||
def getFileLineNum(project_path,file_path):
|
||||
|
@ -228,4 +277,5 @@ def getFileLineNum(project_path,file_path):
|
|||
try:
|
||||
return len(open(path,'rU').readlines())
|
||||
except:
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -1318,7 +1318,7 @@ function submit_file_annotation(file_id, line_num, content) {
|
|||
$(".source-addno-panel").remove();
|
||||
show_file_annotation(file_id);
|
||||
}else{
|
||||
alert("您已经添加过注释了")
|
||||
alert(data.msg)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
<span class="fl mt7 info-nav">Comments</span>
|
||||
</p>
|
||||
</div> -->
|
||||
{% if fileid_name_anno_issue %}
|
||||
<div class="fl font-20 colorFFF">Annotated Files</div>
|
||||
<div class="filePathInfo">
|
||||
<div></div>
|
||||
|
@ -99,6 +100,7 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue